Spawn actor in locations from a table

I have a area on the screen where I want images to appear one after the other, and created a table that holds every coordinate (x,y) that would hold the index of each spawn point. I set up a loop to go through the spawn points and spawn the selected actor, but when I test, it only spawns 4 images in the first 4 spawn locations from the table.

I have a self attribute on a Spawn Image actor called IndexSpawnImage as index type. Also tried with a timer instead of a loop, with a rule that changes my index attribute to +1, but that only spawns 2. I cannot figure out why it will not loop through all the positions, I have 98 rows in the table. I watched a video to help me get to this point, but the video removed rows from the table to avoid reusing them, but I don't want to remove rows and I don't think that is causing this particular issue.

Loop over table rows
Start index: First Cell
End Index Last Cell
Store index in attribute self.IndexSpawnImage

Spawn Actor rule
Spawn Actor (img) place: in front of layer
Direction 0 relative to scene
from position: tablecellvalue(game.tbl_Positions,self.IndexSpawnImage,1)
to position: tablecellvalue(game.tbl_positions,self.IndexSpawnImage,2)

Also tried with a timer instead of a loop: (using a different index attribute)

Timer
every 0 seconds, run to completion
Change Attribute
set self.ActorLocation to random(1,tablerowCout(tbl_positions))

Spawn Actor rule
Spawn Actor (img) place: in front of layer
Direction 0 relative to scene
from position: tablecellvalue(game.tbl_Positions,self.ActorLocation,1)
to position: tablecellvalue(game.tbl_positions,self.ActorLocation,2)

The other part that I am struggling with is that the images I want to spawn there are 7 of them, and although in the above section I specifically selected one image for actor, I would like to pull a random one from a table of image names. Cannot seem to do that either, the images come out white blocks.

Any help would be appreciated, I am new to GameSalad!

Comments

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922

    Firsts it's always best to post a shot of the code. You say spawn rule? What are the conditions of the rule controlling the spawner?

  • Sunni198Sunni198 Member Posts: 7

    I wrote all the code/conditions out. the attach file/image does not seem to be working, looks like an empty text box, it wont let me upload the image. Not sure how else to get the image here.

    the conditions of the rules are when a button is touched (note there are two examples here, one loop and one timer.) Also, these are nested inside the Do function of when a button is touched. the spawn actor rules are nested within the loop or timer functions.

    the conditions of the rules controlling the spawners are:

    Timer example
    Spawn Actor (img) place: in front of layer
    Direction 0 relative to scene
    from position: tablecellvalue(game.tbl_Positions,self.ActorLocation,1)
    to position: tablecellvalue(game.tbl_positions,self.ActorLocation,2)

    Loop example:
    Spawn Actor (img) place: in front of layer
    Direction 0 relative to scene
    from position: tablecellvalue(game.tbl_Positions,self.IndexSpawnImage,1)
    to position: tablecellvalue(game.tbl_positions,self.IndexSpawnImage,2)

  • Sunni198Sunni198 Member Posts: 7
    edited July 2015

    An update, I moved the loop out of the touch rule. when I preview, it now spawns all the icons as it should through the loop, upon opening with no trigger. Not quite sure why it will not do this with a trigger of a button touch, it only spawns a few of them.

    Found this post: http://forums.gamesalad.com/discussion/86756/loop-over-table-doesnt-work-if-placed-within-a-rule

    Makes complete sense, however I created an attribute that will toggle StartGame true/false. I nested my loop into a rule that If that attribute is true to start the loop. Then created a button that changed the attribute to true when pressed. nothing happened. i'll keep working on it..

  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    edited July 2015

    You can put a rule inside a loop. Plus when you posted your code look, you didn't put the conditions. conditions are when touch is pressed, if attribute X = 120 et.. you posted the behaviors inside the rule but not the conditions.

Sign In or Register to comment.