For loop DEMO

firemaplegamesfiremaplegames Member Posts: 3,211
edited November -1 in Working with GS (Mac)
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

Comments

  • RattleheadRattlehead Member Posts: 485
    firemaplegames said:
    Attempting a grid-based puzzle game without Arrays and Loops is an exercise in torture.

    Hopefully this helps somebody down the painful path of creating puzzle games with GameSalad!

    Soooo... what you're saying is that your demo is the iron maiden for which people can spend an enjoyable evening? :)

    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.
  • JackBQuickJackBQuick Member Posts: 524
    Thanks, Joe! I can't wait to get home and try this out to see what you've done!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    Don't get too excited! It's no biggie, but maybe it can help somebody out.

    @rattlehead: yes, Arrays, loops, text manipulation, concatenation, etc.. would really open the doors to a lot of types of games.
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Joe, You use a `Every 0 seconds` timer in your loop. This causes the grid generation to take a little while. Can you think of a way to accomplish the same thing (near) instantly?

    Thanks!
  • BarkBarkCoBarkBarkCo Member Posts: 1,400
    Figured it out. I am using a controller to start the block generation, and then the blocks themselves generate the next block. No timer needed that way and everything gets created instantly. Yay!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    nice!
  • ToastKittenToastKitten Member Posts: 360
    BarkBarkCo said:
    Figured it out. I am using a controller to start the block generation, and then the blocks themselves generate the next block. No timer needed that way and everything gets created instantly. Yay!

    I used this technique in my canvas painting demo a while back, but it didn't seem to work whenever I tested on a device for whatever reason. I haven't tried it in 0.9 so I couldn't really say what'd happen at this point.

    Has this worked on a device for you?
Sign In or Register to comment.