Changing attributes globally

gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
edited November -1 in Working with GS (Mac)
"Insomnia rules OK"!

Seriously, running through more tests this early morning, so as I can slowly get the full swing of GS.

I would want Actor1 to, let's say, rotate; if a boolean attribute of another actor was set to true. I'd be surprised if this can't be done, but I can't find any reference, or work out how to get the contents or state of another actor's attribute within the Rules of my actor.

Can anyone help please?

Edit: Just realised that the title of this post should have been Obtaining another actor's attribute. But to change another actor's attribute from within the Rules of the actor your working with would be great too, if it can be done....

Edit: not sure it could be done, I guess. Probably too many "tangled wires". I wish there was, at least, an attribute called Global Attributes, containing the ability to at least "get" the state of a boolean of another actor. Also maybe to get other actors new attribute variables. Would anyone else agree that'd be useful?

""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

Comments

  • firemaplegamesfiremaplegames Member Posts: 3,211
    Any actor instance in the Scene can get (and set) any other actor instance's attributes.
    Prototypes cannot.

    To test this out, try this:

    Create two new actors, using the [+] button.
    Drag both of them into the Scene and place them anywhere.

    Double-click on Actor 1 in the Scene (NOT the original in the Library) to open its property inspector.
    Click on the padlock.

    Add a Rule, like this:

    Rule
    When all conditions are valid
    Touch is pressed
    -----Change Attribute

    In the Change Attribute behavior, click the little '...' to open the drop down menu.
    Choose: Current Scene=>layers=>Background=>Actor2=>Rotation

    Set it to: 45

    Now preview the game. Click on Actor 1. Actor 2 should rotate.

    You can use this technique to read and set other Actors in the Scene.

    HOWEVER, it is not for the faint of heart! That padlock you clicked was there for a reason! If you do not understand the concept of prototypes and instances, or Rules, attributes, expressions, etc... I don't recommend doing this. It can very easily get complicated, and you will have broken the protoype-instance bond. Plus, if you move those Actors onto different layers, the code will break without you knowing it.

    So it is possible, you just need to be careful.

    When you are starting out with these techniques, I would recommend only ever clicking the padlock of one single actor in a Scene. Use that Actor to read and control other Actors and use their information to set global attributes.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    firemaplegames said:
    Any actor instance in the Scene can get (and set) any other actor instance's attributes.
    Prototypes cannot.

    Phew, I'm pleased about that...

    Thank you for your comprehensive explanation Joe, much appreciated! I'll run through your example soon and then it'll click into place with me, I'm certain.

    ;-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi Joe, had a chance to try out your example.
    firemaplegames said:

    In the Change Attribute behavior, click the little '...' to open the drop down menu.
    Choose: Current Scene=>layers=>Background=>Actor2=>Rotation

    Ah, that's where they're hiding!

    I can see a great potential now, taking your warning + recommendation into account. Thank you again.

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    There's one thing I've just realised: I'm still uncertain if "if" statements, GS style, can be implemented somehow. So I now understand that one actor can change another's attribute, but how could one actor rotate another actor only if a boolean attribute of that second actor was true, for instance; or only when an integer attribute of that second actor was a particular value?

    Example: Current Scene=>layers=>Background=>Actor2=>Rotation

    = 45

    If

    scene..background.Actor2.Size.Width = 23.7

    ? Any additional help appreciated here, thank you.

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • firemaplegamesfiremaplegames Member Posts: 3,211
    Rule
    When all conditions are valid:
    Current Scene=>layers=>Background=>Actor2=>Width = 23.7
    -----Change Attribute: Current Scene=>layers=>Background=>Actor2=>Rotation To: 45

    A Rule is an 'if' statement in GameSalad.
    'otherwise' is the 'else' part of it.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    D'oh! Thank you Joe. Time I was asleep (here in the UK); I think my brain is already!

    :-)

    ""You are in a maze of twisty passages, all alike." - Zork        temp domain http://spidergriffin.wix.com/alphaghostapps

  • CapCap Member Posts: 225
    firemaplegames said:
    Any actor instance in the Scene can get (and set) any other actor instance's attributes.
    Prototypes cannot.
    ...
    So it is possible, you just need to be careful.

    When you are starting out with these techniques, I would recommend only ever clicking the padlock of one single actor in a Scene. Use that Actor to read and control other Actors and use their information to set global attributes.

    To be honest: I never touched instances until now. I always used global attributes for different actors to communicate (e.g. actor 1 sets a global attribute, actor 2 constantly checks for this global attribute).
    As I see it, when instances "talk directly" to each other, this could save some code. Do you think this is more efficient and increases game performance? Then I would probably try this out, too.

    Thanks!
  • firemaplegamesfiremaplegames Member Posts: 3,211
    It' tough to say if it increases performance. When you break the bond by clicking the padlock, you are creating a "rogue' instance. I'm not certain, but I think that "rogue" actor is now counted as a new actor, perhaps adding weight to the game?

    I'm not sure though.

    I haven't tested it enough to know if it increases, decreases, or has no effect on performance.

    Sometimes it's necessary though. And if you need access to the camera data, or you need to control the camera to make it zoom, or pan, or Interpolate, then you NEED to "break" one of the actors, since only a Scene actor has access to the camera.
Sign In or Register to comment.