Are all the Behaviors in GameSalad Synchronous?

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

Comments

  • -Timo--Timo- Member Posts: 2,313
    do you mean when you spawn an actor that it's just working like the prototype? then it is a yes :)
  • KingChaosKingChaos Member Posts: 9
    Thanks for the response @timolapre1998. Although my question is 'general' in nature, a more specific example will probably help get at what I'm asking.

    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



  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Why not have the spawned actor increase the game attribute? so make it copy the current number then after a code cycle .03 of a second have it increate the number.
  • KingChaosKingChaos Member Posts: 9
    Thanks @FryingBaconStudios.

    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?
  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880
    In the distant past, there were posts that indicated that GS ran sequentially. That is, actors run from the bottom upwards. (So the last actor to get time to fire its behaviors would be the one stacked on the front of all the rest.)

    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.
  • tenrdrmertenrdrmer Member, Sous Chef, Senior Sous-Chef Posts: 9,934
    Generally no everything runs close to instant. though it is possible to get many things going at once and something negate a rule down the list by its own actions firing first.

    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?
  • natzuurnatzuur Member Posts: 304
    It is possible for it to fall out of sync because you are essentially running two seperate functions that have no corrolateon to each other, and no dependency on each other. At any given time the processing order of these could change because different things are firing all the time and priorities are going to change. If your looking for micro control over your logic, at a hardware level, probably look into a "C" language.

    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.
  • KingChaosKingChaos Member Posts: 9
    Thanks @RThurman and @tenrdrmer, I didn't know that the actor ordering was important so I will keep that in mind and give it some more thought. Are the inner workings of GS and how it processes 'your' code documented anywhere (other than in the forum messages)? For example, I read that timers run in separate threads and I'm wondering what special considerations I need to make for my code that is in a timer (I have seen some strange behaviors in my 1 week learning GS although it was probably pilot error).

    @natzuur thanks for the suggestion on the time attribute and using it as a time trigger.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    @kingchaos you're kinda over thinking it. Just layout you logic properly and you'll be fine. Keep the order right as @tenrdrmer said and all will be okay. Gamesalad is a straight logic editor with the ability to do complex math in expressions. That's it don't over think it.
Sign In or Register to comment.