using tables for images to loop

digitalzerodigitalzero Member, BASIC Posts: 639

okay, so im trying to loop my table and im using images of course... was wondering how i could get the table to go back to 1 as opposed to going to 0... its for a character select type of dealio

Comments

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @digitalzero

    maybe post a screenshot of your current code so we can make suggestion based on that.

  • digitalzerodigitalzero Member, BASIC Posts: 639

    absolutely....

  • digitalzerodigitalzero Member, BASIC Posts: 639

    @Hopscotch the first image is where you change the character and the second one is what character its going to display... but using that method it goes back to 0 instead of going to 1

  • HopscotchHopscotch Member, PRO Posts: 2,782

    @digitalzero

    assuming you want to cycle through 11 items, use

    game.which character % 11 +1

    even better, since GS keeps threatening to depreciate the % operator

    mod( game.which character, 11)+1

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    The difference is that (game.which character+1)%11 keeps adding one up to 10 and then resets to 0: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0, 1, 2, ...

    ... while (game.which character%11)+1 keeps modding the value from 0 to 10 and then adding 1 to it: 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 1, 2, ...

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    By the way, if you have a Mac, you can use Spotlight to test mathematical expressions. For example, if you enter (1+1)%11 you'll get 2 and if you enter (2+1)%11 you'll get 3 and if you enter (3+1)%11 you'll get 4, etc.

  • digitalzerodigitalzero Member, BASIC Posts: 639

    HEY @tatiang !!!!!!!!!!!!!! I HOPE YOU REMEMBER ME! anywhos... i have no idea what spotlight is my friend... and also the code really worked for me! the only thing is that i also have a back button too so players are able to switch between a left and right button so essentially game.character-1)%11 is there a way to go back at all? i hope you understand what im talking about

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    Yes, I remember you :)

    Spotlight is the search function on your Mac. You access it by clicking the magnifying glass at the top-right of the screen (menubar) or by pressing cmd+space.

    I don't know a way to loop backwards using just a mathematical expression though there probably is a way. I usually just do this:

    When game.which character>1
         Change attribute game.which character to game.which character-1
    Otherwise
         Change attribute game.which character to 11

  • digitalzerodigitalzero Member, BASIC Posts: 639

    Thank you so much @tatiang

Sign In or Register to comment.