Constraining an actor to a table

Here's the setup

I have a tower game that uses a table for towers and a table for enemies

How can I constrain a id of sorts so that I can access the actors attributes via the table. I want to use table row value when added but when an actor is destroyed and the rows shift the row numbers all change

How can I change all of the ids when an actor is destroyed , or is there another way to do this that I am overlooking?

These enemies are all spawned, so if the answer is row labels then is there a way to change the label names dynamically and also call them from the actor?

Thanks in advance for any help you can provide!

Comments

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I made two demos that do this sort of thing:
    http://forums.gamesalad.com/discussion/comment/383521/#Comment_383521
    http://forums.gamesalad.com/discussion/comment/384027/#Comment_384027

    The general idea is to increment a game attribute right before spawning an actor and then have the actor grab that game attribute and assign it to a self attribute. That self attribute then gets used throughout the game to change or check table row data (the attribute is the # of the row assigned to that actor).

    I don't know if I've ever used that system to also remove an actor's row. One thought is just to blank out the row and not use it. But if you're also making use of the tableRowCount() function then you need to keep things neater than that. Honestly, I find it challenging to remove a row and keep everything synced.

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

  • jmachado999jmachado999 Member Posts: 52
    Yeah it's the removing that is the issue.

    I was sleeping on this and now I am thinking that maybe when the actor is destroyed I can pass the id of the destroyed actor back to the scene. After that check that value against the contents of the table and if any ids are greater than the value then -1 them. At the end of the loop change the value to row count or set another value to false.

    I feel like there must be an easier way but I think that may work.
  • jmachado999jmachado999 Member Posts: 52
    I almost feel like zeroing out is a good idea but is there a maximum to table row count? I plan on having hundreds of enemies spawning, and zeroing feels like not great code.
  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949
    I almost feel like zeroing out is a good idea but is there a maximum to table row count? I plan on having hundreds of enemies spawning, and zeroing feels like not great code.
    You can have over a thousand rows. And even though it might not seem as ideal, there's really no problem with the code as long as your actors are syncing to their own rows. They'll just ignore the zero'ed rows.

    I like your idea of each actor checking a game idea to see if they are higher and subtracting one. I'll be curious to know if that works.

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

Sign In or Register to comment.