How do I programme Next and Previous buttons

Get help using Construct 2

Post » Sat Jul 18, 2015 10:52 am

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
B
11
S
3
G
2
Posts: 36
Reputation: 1,811

Post » Sat Jul 18, 2015 11:15 am

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)
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Jul 18, 2015 12:28 pm

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. =]
B
11
S
3
G
2
Posts: 36
Reputation: 1,811

Post » Sat Jul 18, 2015 12:52 pm

Glad I could help. :)

Good luck with your Game/app!
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775


Return to How do I....?

Who is online

Users browsing this forum: lolsuperscratch, RobertMKD, tarek2 and 10 guests