How do I programme Next and Previous buttons

0 favourites
  • 4 posts
From the Asset Store
A set of retro 16-Bit Neon UI elements to make your menus pop!
  • Hey guys,

    Can I please get some help? I've been working on this problem for 3 flat days, I've tried searching everywhere on the internet to try and find something that can help me do the same thing I am after and I can't seem to find it.

    Here is what I have:

    http://prntscr.com/7u31yk

    Just to explain what's going on here: I have a 1D array. It is listing a fire or a money bag that appears in the game. The fire and money bag appear at random. The elements in the array are being pushed back on the X axis whenever a money bag or a fire is created, so in the screenshot you see here, number 6, which says "Fire" was the last thing that was spawned in the game. The game will continue to increase the size of the X axis for each thing that is spawned in the game for example, the next thing that appears will be at 7, then the next at 8 etc.

    In the game, I want to be able to display this a very specific way, and this is how:

    http://prntscr.com/7u31vh

    Where X will display whatever the text at it's co-ordinate is.

    The idea is getting those next and previous buttons to function. If I press next, and I'm at X1, it should go to X2, then if I press it again, it will go to X3, and so on down the X axis. I only want it to display the one X, not more than one.

    And I've tried to do this by doing the following code:

    http://prntscr.com/7u34ll

    So here is my problem:

    This code allows me to go to X2 from X1 (which displays the word Fire), but it will not go further than that. I know I could just copy the code from +1 to +2 and so on and so forth, but that will mean that the player will only be able to view a limited amount of X, I don't think that's the answer, and I don't want to do it like that because the game is designed to extend the X axis indefinitely.

    I've tried countless possibilities with this, and I'm having trouble getting it right. I can't remember everything I have done, however, this is the closest I am able to get it at the moment.

    If anyone can help get my Next button to work, I would really appreciate that. I can then apply an opposite formula for the previous button and that would resolve my problem.

    Your help is much appreciated, and I mean really appreciated. If you like, I'll be sure to provide a 'Thanks to [Your Forum name]' message somewhere in my game if you help get it right for me.

    Thanks bunch! =]

    Regards,

    Luke

  • Why not just use a global variable instead of curX..

    on next pushed

    add one to global variable

    set text to array.at(global variable)

  • So using LittleStain's advice, I have done the following:

    System: Every Tick

    set text to array.at(global variable)

    Next on clicked:

    Add 1 to Global Variable.

    I have also applied the same principle for the previous button (subtract 1 to Global Variable instead of adding to).

    It worked! Omg! I've been trying to work this out for days, I knew every time I thought about using global variables in conjunction with my array was the answer, but I couldn't get my head around it. Thank you so much, LittleStain! You're a legend!

    As promised, I have put your name in my coding to remind me to provide special thanks to you for your assistance. =]

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Glad I could help.

    Good luck with your Game/app!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)