Changing attributes globally
gyroscope
I am here.Member, Sous Chef, PRO Posts: 6,598
"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?
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
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.
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
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
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
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.
:-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
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!
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.