How to make a table not select the same value after it is copied?

Slayre77Slayre77 Member, PRO Posts: 115

A while ago, I asked how to make a value not be selected twice when randomly selecting values. @tatiang‌ helped me out a lot (Deleting rows off a table once the row has been selected). However, the game Im working on is an endless runner, so the table values which correspond to the pattern of enemies spawning cant just stop when all the rows have been deleted. So, once the rows are deleted, I used Copy Table to restore the table . However, there is nothing stopping it from selecting the same value twice (the last selected value in the previous table and the first value of the copied table). So 2 waves of enemies spawn in the same pattern, and I dont want that happening. Any help is appreciated, thanks and sorry if my question is hard to understand

Comments

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

    There are probably complex ways to avoid this but what comes to mind is just (assuming you're grabbing X or Y positions from the table):

    Change Attribute self.lastYposition to game.newYposition
    Change Attribute game.newYposition to tableCellValue(tableName,self.randomRow,1)
    When attribute game.newYposition = self.lastYposition
    Change Attribute game.newYposition to tableCellValue(tableName,self.randomRow,1)

    Obviously, that's not the whole set of behaviors (you'd need the randomization, table row deletion, etc.) but I hope it makes sense. The pseudocode would be:

    1. Store current Y position
    2. Generate new Y position from table
    3. If new Y position is same as current Y position then generate new Y position from table

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

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    I made a tutorial specifically for this:

  • Slayre77Slayre77 Member, PRO Posts: 115

    @tatiang actually, Im taking a number off the table which corresponds to the pattern of enemies.
    @Braydon_SFX‌ I understand your tutorial but I dont quite know how to modify what you did in the video to make my game work. How do I make the value be selected every 1 second? And which attribute in the video should be the attribute that decides which enemies to spawn in my game?

Sign In or Register to comment.