For loop DEMO
firemaplegames
Member Posts: 3,211
Hey all,
Here is a demo showing how to create a nested for loop in GameSalad using a Timer:
http://gamesalad.com/game/play/74268
This demo dynamically generates a checkerboard, sets each square's color, and gives each square a unique name based on its grid position.
Being able to traverse nested for loops is a critical function of grid-based puzzle games like Tetris, Bejewelled, Bust-A-Move, etc...
In code, a grid of objects is usually constructed from a 2-dimensional Array, which is actually an Array of Arrays.
An Array looks like this: myArray = ["lions", "tigers", "bears"]
And I can access the Array like this: myArray[0] = "lions"
(Arrays are zero-based, so the first element in an Array is the 0 position.)
A 2-D Array looks like this: my2DArray =[ ["lions", "tigers", "bears"], ["birds", "bees", "fish"]]
And I can access a 2D Array like this: myArray[1][1] = "bees"
GameSalad does not currently have an Array data type - or a proper Loop for that matter, but this is sort of a way to simulate it.
Attempting a grid-based puzzle game without Arrays and Loops is an exercise in torture. But maybe this will give you some ideas.
Hopefully this helps somebody down the painful path of creating puzzle games with GameSalad!
Feel free to use this for whatever you want!
Joe
Fire Maple Games
Here is a demo showing how to create a nested for loop in GameSalad using a Timer:
http://gamesalad.com/game/play/74268
This demo dynamically generates a checkerboard, sets each square's color, and gives each square a unique name based on its grid position.
Being able to traverse nested for loops is a critical function of grid-based puzzle games like Tetris, Bejewelled, Bust-A-Move, etc...
In code, a grid of objects is usually constructed from a 2-dimensional Array, which is actually an Array of Arrays.
An Array looks like this: myArray = ["lions", "tigers", "bears"]
And I can access the Array like this: myArray[0] = "lions"
(Arrays are zero-based, so the first element in an Array is the 0 position.)
A 2-D Array looks like this: my2DArray =[ ["lions", "tigers", "bears"], ["birds", "bees", "fish"]]
And I can access a 2D Array like this: myArray[1][1] = "bees"
GameSalad does not currently have an Array data type - or a proper Loop for that matter, but this is sort of a way to simulate it.
Attempting a grid-based puzzle game without Arrays and Loops is an exercise in torture. But maybe this will give you some ideas.
Hopefully this helps somebody down the painful path of creating puzzle games with GameSalad!
Feel free to use this for whatever you want!
Joe
Fire Maple Games
Comments
Just kidding. I think this is a great demo Joe and an even better reminder of functionality that GameSalad will eventually need to incorporate. Arrays/lists are necessary. End of story.
I would warrant that I'd like to see arrays added to GameSalad almost as much as QS would like to see a pause function. I said almost. I'd never want to push the most wanted feature off the list of the sheep.
@rattlehead: yes, Arrays, loops, text manipulation, concatenation, etc.. would really open the doors to a lot of types of games.
Thanks!
Has this worked on a device for you?