Are all the Behaviors in GameSalad Synchronous?
KingChaos
Member Posts: 9
When you call a behavior in GS, for example 'Spawn Actor', is it 'guaranteed' to have spawned the actor including running all of the actors initial rules, conditions, behaviors, etc. before it returns control to the calling code? I'm setting my own Game Variables before I call 'Spawn Actor' so I'm wondering if I can assume that when the actor starts up if it can rely on those variables being unchanged from when I set them.
If this is documented somewhere please let me know as I'm trying to figure out how GS works.
Thanks,
Steve
If this is documented somewhere please let me know as I'm trying to figure out how GS works.
Thanks,
Steve
Comments
✮ FREE templates at GSinvention ✮
✮ Available for hire! support@gsinvention.com ✮
So I have a timer that fires every 0.1 seconds and it increments a Game level attribute. This attribute is just a counter that I use so I know how many actors have been spawned and also so that each spawned actor can have a unique value to do look-ups in a table that I have created. Then the timer will then spawn an actor with the hope that the actor will copy this counter value before the timer increments the counter again.
It seems to work but I'm wondering if there is a possibility of the timer going off again before the actor that was just spawned has had a chance to copy the attribute to its instance. Or is all of the code run synchronously and I don't need to worry about being preempted or deal with asynchronous issues?
Thanks,
Steve
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
That sounds like it would work as well but I'm really asking if I need to worry about synchronization issues. In the suggested method you gave, would it be possible for two actors to be spawned in parallel and both grab the same number? I'm not saying this is a problem and certainly I have not seen it and I'm trying to get my head around how GS behaves. I just read on another post that GS timers are in separate threads... I would assume there would be contention issues between multiple timers / threads or code running in parallel accessing the same shared variables but I can't find any posts on this. Do you know if there any 'official' documents on how GS processes / runs your code?
But behaviors within each actor run from the top to the bottom.
So... if this is true then yes, there might be the potential for certain attributes to be accessed (and modified) before you might want them to be. You will need to think carefully about the order of actors, and the order of the behaviors within each actor.
So in a technical answer No everything is not fully 100% in sync. however most cases its not a problem. If you run into a problem just remember how GameSalad actually works under the hood. The Actors are read from the bottom actor in the bottom layer to the top. and each of those actors rules are read from the top down. So if you ever have an issue where a rule is happening to fast move it down the list inside its own actor or move the actor up in the scene layers.
Make sense?
in @FryingBaconStudios suggestion it wouldn't matter because actor A would change attribute X to X+1, same with actor B, so either way you end up with +2 from the actors.
If you're looking for a reliable timer trigger, use a "time" attribute such as device clock, game time, self time, etc. Since these are expected to always run and continue counting reliably for telling time, they can be used in equations that require precise timings.
@natzuur thanks for the suggestion on the time attribute and using it as a time trigger.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS