#### Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

# using tables for images to loop

Posts: 620Member, BASIC

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

• Posts: 2,769Member, PRO

@digitalzero

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

• Posts: 620Member, BASIC

absolutely....

• Posts: 620Member, BASIC

@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

• Posts: 2,769Member, PRO

@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`

• Posts: 11,293Member, Sous Chef, PRO, Senior Sous-Chef

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, ...

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• Posts: 11,293Member, Sous Chef, PRO, Senior Sous-Chef

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.

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• Posts: 620Member, BASIC

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

• Posts: 11,293Member, Sous Chef, PRO, Senior Sous-Chef

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

New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

• Posts: 620Member, BASIC

Thank you so much @tatiang