Question about arrays

rjh5000rjh5000 Member Posts: 22
edited November -1 in Working with GS (Mac)
I would like to make an array of 5 actors, but I am having trouble working out how to do this.

Then I have it so that the first actor is displayed.

I would then like to make it so that every time it is touched it cycles through the images, and then when it reaches the 5th image it goes back to the first.

A global variable will be changed along with the images, which also needs to change value between 1 and 5, then back to 1 and so on

normally I would do something like this

if var = 0 {

currentimage = currentimage + 1
currentimage = currentimage mod 5

image_index=sprite[currentimage]

}

Is something like this possible?

Thanks in advance

Comments

  • JohnPapiomitisJohnPapiomitis Member Posts: 6,256
    we dont have arrays, but you dont need arrays for that just your modulus which we have. this is how to do it:

    make a attribute called currentimage

    make a rule when touch is pressed change attribute currentimage to (currentimage+1)%6

    thats your modulus right there. everytime its pressed it will add one till it reaches 5, then once its 5 and pressed again it will recycyle back to 0. then just have rules when attribute current image =0 change image to whatever, when current image=1 change image to whatever and ect and keep going up to 5

    cheers
  • rjh5000rjh5000 Member Posts: 22
    Cheers for that, I thought there would be a command to do it somewhere.

    Thanks for your help
Sign In or Register to comment.