Dont spawn more than once in one spot?

FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148
edited January 2015 in Working with GS (Mac)

So I have a spawner set up to spawn (I guess you could call them) "enemies". Heres what I have

Timer
Every 1 seconds spawn actor Dart A in front of actor, In direction 0 relative to scene, from position [tableCellValue(game.Spawn Table, 1, random(1,4))] [907]

so they are all spawning at Y=907, and they are varying between 4 different x values, which are selected from a table with only 1 row and its picking from columns 1-4.

How can I prevent it so that it wont spawn repeatedly in one spot, because I have had times where it goes on a streak of just spawning in one of the 4 spots like 5 or 6 times. I would like to limit it to only 2 or 3 times max in one spot, or atleast make it so that it will never spawn in the same place twice.

Possible?

«1

Comments

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    Does anyone have a solution to this?

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

    The number of possible combinations of 4 values is 24 (4!):

    1234
    1243
    1324
    1342
    1423
    1432
    2134
    2143
    etc.

    Set up a table with 24 rows and 4 columns where each column has a single digit. Then when you pick a random row, spawn at the x value in column 1... then column 2... then column 3... and finally column 4. Once you've exhausted that row delete it from the table, pick another random row and repeat.

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

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    And how would that look in the code?

    I have made out the table, 4 columns, 24 rows with all variations.

    Would it be

    from postition: [tableCellValue||game.SpawnTable||, random(1,24), 1-4]

    Basically im asking about the 1-4 part, what do you put there in the code so that it executes columns 1 through 4 in order then moves on to picking another random row to go through.

    (oh and PS i dont plan on doing the delete row thing, because I want this to go forever, and I dont mind it picking the same row again)

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    So I have a table with 24 rows, and 4 columns. I want my spawner to pick a row randomly, and then execute each column in order within that row, then move on to randomly selecting another row.

    So I have on my spawner


    from position: [tableCellValue(||game.Table||, random(1,24), and then what do I put here for the column???]

    do I put 1-4 to mean column one through four, or does that mean 1 minus 4. What do I put there for the column that would make it go in order and do all 4 columns before moving on to randomly selecting another row.

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

    Please don't create new threads for the same issue.

    /merged

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

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

    from postition: [tableCellValue||game.SpawnTable||, random(1,24), 1-4]

    You could use Loop over Table and loop over the columns or you could just spawn an actor and then increase an attribute such as self.NextRow to self.NextRow+1 and use that in place of the column value in the tableCellValue expression.

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

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    Sorry I'm not sure what you mean. I put self.NextRow in for the column, as well as tried self.NextRow+1 and neither of those seem to work.

    Is there no way to to make it go in order column 1 then 2 then 3 then 4 within the row it randomly chose, then after thats done move on to randomly selecting a new row. What exactly am I supposed to put in for the column...?

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

    Sorry, I meant self.NextColumn... anyway, just an integer attribute that you increase after each spawn and then once you reach 4, you reset to 1 to start with the first column of another randomly selected row.

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

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    Ok, so I have been away for a few days, just getting back. I don't know why but something about this particular issue my brain is just mushing trying to wrap my head around this. Like this spawner probability stuff is effing with my head :).

    I don't mean to be continually burdensome, but if you could lay this out step by step what you intend to happen in each system. I have the table of values, I have been experimenting endlessly with rules and things. I don't quite get what you mean with your wording here.

    If possible: Exactly what rules do we have, where and how are things being entered with what attributes in what objects. Try to be explicit.

    Sorry I have had a firm grasp on every other issue but this spawner stuff really stumps me.

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

    I don't have the time to go through it step by step but I can attach a demo for you.

    You didn't specify Mac or PC. This was created on a Mac.

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

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    Thanks a lot, I'm working with it now and I'll get back to you tomorrow. Appreciate the help immensely. This spawner is my last large hurdle to get over, then I can focus more on art and other things.

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

    You're welcome. Here's a CSV file that contains the 24 possible permutations (generated from data at http://textmechanic.com/Permutation-Generator.html).

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

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    That's ok, I created a table with over 48 values, 24 of them were the 24 possible combinations, the other 24+ were combinations where there are only 2 in a row.

    Testing the demo you sent now

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148
    edited January 2015

    So I thought I had come up with a simpler system.

    The spawner is supposed to spawn the actor at one of the 4 positions every 0.4 seconds; & Like I said I have the table of values with 48 rows and 4 columns.

    So I made 2 rules, RowNumber & ColNumber. 1.6s is the amount of time that it would take for the spawner to spawn 4 actors at each of the 4 column positions in a row. So, Every 1.6 seconds, it changes the attribute RowNumber to random(1,48).

    (this column part is a little confusing on paper so im going to write it out more like it looks)

    Every 1.6 seconds
    {
          After 0.4 seconds
          {
                 Change ColNumber to 1
          }
          After 0.8 seconds
          {
                 Change ColNumber to 2
          }
          After 1.2 seconds
          {
                 Change ColNumber to 3
          }
          After 1.6 seconds
          {
                 Change ColNumber to 4
          }
    }
    

    Then, for the spawning.

    Every 0.4 seconds, spawn actor Enemy from position X=[tableCellValue(game.spawntable, game.RowNumber, game.ColNumber)] and Y=1050

    So I load up the game... and all the enemies are spawning at X=0 and Y=1050.

    Where is my logic broken?

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

    A simpler timer set up might be:

    Every 1.6 seconds
    Every 0.4 seconds
    Change attribute game.ColNumber to game.ColNumber+1

    By the way, if you have an every 1.6 seconds timer set to do something after 1.6 seconds, I'm not sure it will actually do that behavior. Does game.ColNumber ever equal 4 when you Preview it?

    So what you've deduced is that tableCellValue(game.spawntable, game.RowNumber, game.ColNumber) always equals zero. Check to make sure you selected game.spawntable from the drop-down menu and didn't just type it in. Use Display Text behaviors or Log Debugging Statements to watch the value of game.RowNumber and game.ColNumber to make sure they are changing. Double-check your table values to make sure you don't have any zeroes (I'm guessing you don't).

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

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

    sigh I don't know why Markdown formatting is all of a sudden double-spacing code blocks. :s

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

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    As I continue to try and figure this out, may I just suggest a more compitent or other versions of the Spawner attribute would be awesome. Ones where you could enter in multiple X&Y values to spawn from, and specify things like the amount of times its allowed to go from one point. I know its a little specific, but I feel like its broad enough to warrant a feature, but that's me.

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    or atleast a "random without repeats" function. A random function that will pick at random what you have specified, but wont pick the same thing twice until all options are selected.

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    So I have been at this for almost weeks now trying to figure out how to make a spawner that spawns actors to 1 of 4 different x coordinates (all the same Y coords) every 0.4 seconds, and force the spawner to never repeat the same location twice or more in a row.

    Seems basic, but it's been a huge pain.

    To get all caught up on whats happening go here:
    http://forums.gamesalad.com/discussion/76484/dont-spawn-more-than-once-in-one-spot#latest

    I am going away for a few days and wont be able to work on this, so I thought I would open this up to the GS community to see if any of you could solve this. I have stripped away all graphics and everything and have created a very simple project here to work in. It has the spawn table and everything.

    https://www.dropbox.com/s/2xxn80gns3vmvn7/Random Without Repeats.zip?dl=0

    If any of you are skilled enough to solve this I would be forever grateful.

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148
    edited February 2015

    Hey tatiang

    So, before I go, I thought of this possible solution.

    Every 1.6 seconds
    {
           After 0.3 seconds
           {
                 Change Attribute: ColNumber to 1
           }
           After 0.7 seconds
           {
                 Change Attribute: ColNumber to 2
           }
           After 1.1 seconds
           {
                 Change Attribute: ColNumber to 3
           }
           After 1.5 seconds
           {
                 Change Attribute: ColNumber to 4
           }
    }
    

    But it appears that I'm still getting the same every thing is spawning at x=0 problem.

    Oh and the fact that everything is .1 seconds before it is supposed to pull from that value is to try and compensate to make sure that the number is what its supposed to be before it selects it. Not sure if that was necessary.

    Im not totally familiar with logging things in the debugger and monitoring them. If you could refer me to a forum about that that would be really helpful, and I'll take a look at it when I get back.

    If you want to take a stab at it yourself you can download a stripped away simplified version I made a few hours ago and see if you can come up with it yourself.

    https://www.dropbox.com/s/2xxn80gns3vmvn7/Random Without Repeats.zip?dl=0

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Threads merged.
    Please don't make make multiple threads for the same topic.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    You might be overthinking things. You basically want to have enemy actors spawning at any one of four locations. But you don't want the same locations to repeat right next to each other. Here is an example of how to do that.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Perhaps you want to ensure that all four locations get randomly spawned before it resets with a new round of spawns. And you want to use a table to keep track of which location to spawn at. Here is an example of how to do that.

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    Ok, you seem to have figured out the issue, I just am not sure how to modify your work to work with a specific set of 4 coordinates. Or in other words, my 4 X coordinates are 102, 289, 476, and 663 (ipad landscape) All 4 coordinates are 187 apart

    So how would I adjust the formula to make it work with those.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    edited February 2015

    You can change the table to the numbers you want (102,289,476,663). Then delete the "*125" in the x-coordinate of the sawn behavior. Instead, it will be:
    tableCellValue( game.Table 1 , self.counter +1,1)

    That should do it!

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    Any reason why the scramble stuff is repeated so many times, and any particular significance with the amount of times the "Scramble the table numbers" group is repeated 5 times, and then 5 times again if the counter = 0

    Just want to clarify if this system works infinitely.

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    The scramble numbers group was just a cheap way to shuffle the numbers. Its just choosing a table cell (at random) and moving the number in the cell to the beginning of the table.

    It does this 5 times because there are four table cells. I just wanted the numbers to be mixed up enough.

    It shuffles them (to randomize them) the when it starts. Then it shuffles them again whenever the counter resets to zero.

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    So I've copied what you have done exactly, and I just get all the actors spawning at X=0.

    Ive been through each thing a hundred times trying to look for what could be different, can't find a thing. Ive created the rules in the spawner actor, they are all 3 integers defaulted at 0.

    Can't seem to find what would be wrong.

    Is there anything that needs to be adjusted to work in another program. It seems to be running just fine in your project...

    hmmm

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Whenever an expression is not right, it defaults to "0". I suspect that there might be a missing parenthesis or a missing comma, something like that.

    It could also be that you typed the values directly into the fields, instead of opening up the expression editor. You need to hit the little 'e' symbol and then build the expression by using the drop down menus.

  • FlyboyTrevy_FlyboyTrevy_ Member, PRO Posts: 148

    The text being displayed in the actor are all zeroes too.

    And yes I have removed the *125 and replaced the coordinates in the spawn table.

Sign In or Register to comment.