Destroy "any" Actor

gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
edited November -1 in Working with GS (Mac)
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?

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

Comments

  • design219design219 Member Posts: 2,273
    That would be real handy is some situations.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Exactly what I thought, design219! Thanks for your reply. I'll post the idea into Suggestions, I think.

    :-)

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

  • I_MOODOOI_MOODOO Member Posts: 7
    You can manage this with global attributes. Create an attribute like “Globaldeath”. Give the attribute the value FALSE or 0. Give all actors a rule like this. If “Globaldeath” is TRUE or 1 then destroy actor. Now you can destroy all actors with one event (if … then change attribute “Globaldeath” to TRUE or 1).

    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.
  • scitunesscitunes Member, Sous Chef Posts: 4,047
    you could take the above rule set and save it in "my behaviors" and then it would be just as easy as having it as a premade behavior
  • ORBZORBZ Member Posts: 1,304
    How could that work? You can't reference an instance of an actor in the pulldown unless it's already in the scene. In which case it would be a scene only behavior. Which further complicates things if the Destroy is called twice since the first time it's called it would destroy the only instance referenced in the pulldown. The second time it's called it would be pointing to a null reference.

    Unfeasible.
  • firemaplegamesfiremaplegames Member Posts: 3,211
    In object oriented programming, you generally do not want one instance to control another. You usually want all the instances to be autonomous.

    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
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Thanks all, including your detailed explanation, Joe, thank you, interesting stuff. All excellent for destroying one, some or all instances of the same Prototype.

    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

  • firemaplegamesfiremaplegames Member Posts: 3,211
    It doesn't necessarily have to be instances of the same Prototype...
    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.
  • gyroscopegyroscope I am here.Member, Sous Chef, PRO Posts: 6,598
    Hi Joe; so impressed with that, I am! Thank you muchly, that's been very useful to learn.

    :-)

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

Sign In or Register to comment.