Destroy "any" Actor
gyroscope
I am here.Member, Sous Chef, PRO Posts: 6,598
Hi, do you think that if the Destroy Behaviour placed in the Rules had a pulldown menu to choose any actor to be destroyed, that'd be a useful thing? Or maybe there's a reason why Destroy only has "Destroy this actor"...
Anyone any thoughts on this?
Anyone any thoughts on this?
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
Comments
:-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
If you need this more the one time, than control this with a timer. (if … then change attribute “Globaldeath” to TRUE or 1 >>>for 0.1 seconds).
“…” is any event like collide or else.
Unfeasible.
In other programming environments, there is a concept of a 'getter' and a 'setter'. Every instance would have getters and setters for the Attributes that you want to expose to the outside word, or to other instances. i.e, "please get me your current X coordinate", or "please set your color to red".
It is sort of a 'polite' way to control, or to get information from other instances.
It's a subtle concept, but it prevents bugs from creeping into your software. If you have every actor controlling every other actor, things can start to get out of control.
A real-world example would be something like this:
Let's say you and I are both instances in the world.
The problem I need to solve is, "What did you have for lunch?"
There are two ways I could go about this. The first way, the brute force way, would be for me to reach inside your stomach and actually see what you had for lunch...
The second way, or the 'polite' way, would be for me to simply ask you what you had for lunch.
---
The situation you are describing above is very similar to the brute force method. You basically want to Destroy another instance without asking them first. What if they are still in the middle of a task? What if they are critical to some other logic happening? If you ask them first, they have an opportunity to take care of all their affairs before Destroying themselves...
GameSalad does have a way for Instances to use brute force on any other Instance. Any Instance can control or access any other instance's Attributes. But only do that if you really know what you are doing! Those padlocks are there for a reason. Do not click them if you are not 100% certain why you are clicking it.
GameSalad does not have 'getters' and 'setters'. The way GameSalad handles it is to use global Attributes to pass information back and forth.
Let's say you have two instances, a square and a circle. You want the circle to Destroy itself when you click on the square. This is how you would do that:
Create a global boolean game attribute called 'pleaseDestroyCircle'. (without the quotes)
In the prototype of the square Actor, create a Rule like this:
Rule
When all conditions are valid:
Touch is pressed
-----Change Attribute: game.pleaseDestroyCircle to: true
And in the prototype of the circle Actor:
Rule
When all conditions are valid:
game.pleaseDestroyCircle = true
-----Change Attribute: game.pleaseDestroyCircle to: false
-----Destroy
That is how you would pass information back and forth In GameSalad.
Let's say you have a similar situation: You have one square instance and FIVE circle instances. You want it so when you click the square instance, only one of the circle instances will get destroyed. You want the circle to be randomly chosen.
You would do that like this:
Create a global boolean game attribute called 'pleaseDestroyCircle'. (without the quotes)
Create a global integer Attribute called 'randomCircle'. (without the quotes)
In the prototype of the square Actor, create a Rule like this:
Rule
When all conditions are valid:
Touch is pressed
-----Change Attribute: game.randomCircle to: random(1,5)
-----Change Attribute: game.pleaseDestroyCircle to: true
And in the prototype of the circle Actor:
Create an integer attribute called 'myID'. (without the quotes)
And a Rule, like this:
Rule
When all conditions are valid:
game.pleaseDestroyCircle = true
game.randomCircle = self.myID
-----Change Attribute: game.pleaseDestroyCircle to: false
-----Destroy
Now, double click on each of the five circle instances in the Scene and change each one's 'myID' Attribute to the numbers 1 through 5.
Does that make sense? That is the 'safe' way to do what you are asking for in GameSalad.
Hope this helps!
Joe
I'd still like to see a pulldown menu to select a specific different Actor in the Destroy Behaviour though!
:-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps
That was just my example.
It can certainly be any instance in the Scene.
They just need to have Rules that listen for global Attributes changing.
For the Destroy behavior to have a drop-down associated with it, it would have to be in an Instance, as Prototypes do not (and should not) have any idea of what any of their instances would know about.
:-)
""You are in a maze of twisty passages, all alike." - Zork temp domain http://spidergriffin.wix.com/alphaghostapps