Can you link actors without using global variables?

CluvCluv Member Posts: 229
edited May 2012 in Working with GS (Mac)
Is there any way to pass variables between two actors without having to set a global variable? I am trying to keep my variables to a minimum, but I would like to pass certain values from one actor to another. Really, I am spawning characters of the same "type," but who have different attributes. In most cases, the spawn can be instant and I can hide it until it is ready, but I have a few f(x) that don't run right away. Those f(x) pick up the wrong amount saved in the variable for another actor.

I know I can save them to global variables and pass them that way, but I am trying to avoid keeping a bunch of global variables that I don't need. Anyone have any suggestions?

Thanks!
C

Best Answer

  • tatiangtatiang Posts: 11,949
    Accepted Answer
    It depends a lot on how you need to use those attributes. If you are spawning actors, then the only way to pass attributes is with global (game.______) attributes. If you recycle actors by keeping them off-screen until needed and then moving them (change attribute self.position.x/y to...) to an on-screen position, you can unlock the actors and access the Current Scene-->Layers-->[layer name]-->[actor name]._____ attributes.

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

Answers

  • jckmcgrawjckmcgraw Member Posts: 647
    @Cluv

    If an actor is unlocked, I believe that you go to current scene > layers > (layer object is in) > object > (the self.attributes are there).

    That order might be wrong. I'm on a PC now so I can't check.

    Since you are spawning actors they won't be unlocked though...

    Hope this helps,
    Jack McGraw
  • CluvCluv Member Posts: 229
    @jckmcgraw, thanks. Yeah, I need to test the unlock f(x), but I think that I still will have to find a way to keep track of which actor is which when they are unlocked. I want it to be dynamic so that I don't have to manage the linking once the spawn has been completed...
  • CluvCluv Member Posts: 229
    Thanks @tshirtbooth. I will keep my eyes peeled. @tatiang, yeah I spawn them not recycle them. It is an RTS so spawning is essential to the game. In general it works fine. There are just a few cases in the game where spawning an actor lags just enough behind that the actor can pick up the wrong value from the global variable. I was afraid that I am pretty much stuck where I am at without writeable tables. It is totally doable, but I feel like I am making life much harder for myself doing this type of game without the table f(x). I will try a couple of things and see what I come up with. Thanks!
  • CluvCluv Member Posts: 229
    @tshirtbooth, @tatiang, @jckmcgraw, I think I figured it out. It may have even been @tatiang 's response to an earlier thread. I can hold a counter for all actors that will be a defacto, SKU in game. I can pass that value to a new actor, then iterate it. And, if I have another actor of a different type that is linked to it, when I spawn them both, I can pass the same SKU to them before iterating the counter. And seeing as I most likely won't have a huge # of actors, the counter shouldn't have an issue. Thanks for your help!
Sign In or Register to comment.