[SOLVED] How do I create a sensor that stops only certain cannons from firing?

Uuemaich

  • Posts: 52
Okay so I've got a cannon that shoots fireballs and all kinds of stuff that works properly, however I want to create a sensor (like a pressure plate) that when stepped on turns off only certain cannons from firing, possibly settable from the scene editor?

Here's my cannon and fireball behaviors if that'll help. Thanks!

« Last Edit: April 19, 2012, 02:42:12 pm by Uuemaich »

Nomosoft

  • Posts: 122
Add a boolean variable such as "Is Active?" to your cannon. Add something like

If (not IsActive?) {
  Stop;
}

inside your "Do After X Seconds" code, at the top. When the pressure plate is stepped on, set Is Active? to False. When the plate is clear, set Is Active? to True if you want the cannon to stat firing, again.

To shut off certain cannons, add a text or number field like "Unique ID" to your Cannon behavior. In the scene designer, assign a name or number to each cannon. Then, for each pressure plate, you can have something like this:

A list named "Cannon List" which contains the IDs of all he cannons you want that plate to control

(When plate is stepped on...)
For each (Actor of Type "My Cannon") {
  For each (item in Cannon list) {
    If (get _UniqueId from behavior Cannon for Actor of Type == [item from Cannon List]) {
      Set Is Active? to False.
    }
  }
}

Alternatively, you could have something like this in your pressure plate behavior:

An Actor variable named "Controlled Cannon" which you set in the scene designer to point at the appropriate instance of My Cannon.

(When plate is stepped on...)
Set _IsActive? to False in behavior Cannon for Controlled Cannon


Note: If you want the cannon to stay of permanently, use something like this in your Cannon behavior:

(Inside the timer loop)
If (Is Active? == False) {
  Cancel;
}

Uuemaich

  • Posts: 52
I appreciate the help, but I'm still new and learning so I don't fully understand what you mean by these:

Add a boolean variable such as "Is Active?" to your cannon.

Do you mean a blue attribute, or the purple one, a game attribute?

When the pressure plate is stepped on, set Is Active? to False. When the plate is clear, set Is Active? to True if you want the cannon to stat firing, again.

If I use a blue attribute in the cannon behavior, how do I control when the pressure plate has been stepped on from a different behavior?

To shut off certain cannons, add a text or number field like "Unique ID" to your Cannon behavior. In the scene designer, assign a name or number to each cannon.

What do you mean by a "Unique ID"?

An Actor variable named "Controlled Cannon" which you set in the scene designer to point at the appropriate instance of My Cannon.

Can you explain this a little bit more, too? Again, sorry, still new and learning. And I really appreciate the help. :)

Derelikt

  • Posts: 92
I appreciate the help, but I'm still new and learning so I don't fully understand what you mean by these:

Add a boolean variable such as "Is Active?" to your cannon.

Do you mean a blue attribute, or the purple one, a game attribute?

When the pressure plate is stepped on, set Is Active? to False. When the plate is clear, set Is Active? to True if you want the cannon to stat firing, again.

If I use a blue attribute in the cannon behavior, how do I control when the pressure plate has been stepped on from a different behavior?

To shut off certain cannons, add a text or number field like "Unique ID" to your Cannon behavior. In the scene designer, assign a name or number to each cannon.

What do you mean by a "Unique ID"?

An Actor variable named "Controlled Cannon" which you set in the scene designer to point at the appropriate instance of My Cannon.

Can you explain this a little bit more, too? Again, sorry, still new and learning. And I really appreciate the help. :)

You can use blue booleans, and set them to true or false from the plate behavior using a (set actor value [  ] to [  ] for behavior [  ]). Also it would a bit easier if you have two different cannons, ones that are not controllable by the plate (normal ones) and others that are controllable (have the booleans etc). I don't know how assign unique IDs yet :P.

Nomosoft

  • Posts: 122
Add a boolean variable such as "Is Active?" to your cannon.

Do you mean a blue attribute, or the purple one, a game attribute?

When talking about adding attributes to a behavior, we're always talking about the blue ones. Game attributes do not belong to behaviors.

When the pressure plate is stepped on, set Is Active? to False. When the plate is clear, set Is Active? to True if you want the cannon to stat firing, again.

If I use a blue attribute in the cannon behavior, how do I control when the pressure plate has been stepped on from a different behavior?

There are blocks that say "for [], set [] to [] for behavior []," which you use to set attribute values in other behaviors. So, your pressure plate would use "for [My Cannon] set [_IsActive] to [False] for behavior [Cannon]." You can use the drop-down arrows inside the blocks to select the behavior name and attribute name. There is also a "get" block for the purpose of retrieving values from other behaviors.


To shut off certain cannons, add a text or number field like "Unique ID" to your Cannon behavior. In the scene designer, assign a name or number to each cannon.

What do you mean by a "Unique ID"?

What I mean is, give a "name" to your cannon by adding an attribute to the Cannon behavior. So, in the Cannon behavior, you would create a number or text attribute called "Unique ID," which you could then assign a value in the scene designer by double-clicking on a My Cannon Actor. So, you'd set "Unique ID" to 10 for one My Cannon, and 16 for another, or whatever numbering/naming system you wish to use. You can then read that "Unique ID" attribute from other behaviors so you know which My Cannon is which.

An Actor variable named "Controlled Cannon" which you set in the scene designer to point at the appropriate instance of My Cannon.

Can you explain this a little bit more, too? Again, sorry, still new and learning. And I really appreciate the help. :)

When you place an Actor in the scene designer, you can double-click on it (or right-click and select "Customize Behavior") and edit the attribute values of the behaviors attached to that actor.  In this way, you could have a behavior called "Switch" with an Actor attribute called "Target," and in the scene designer, you can select an Actor from the scene for "Target" to point to.

Uuemaich

  • Posts: 52
Now none of my cannons are firing and stepping on the plate does nothing. I've obviously done something wrong but I don't know what. XD

Thanks for all of the info though, I'm very thankful for it.

Nomosoft

  • Posts: 122
Alright, I'm not sure why you're using two timers in your first behavior. The way you have it, you're waiting for every Shoot seconds, then waiting again for Delay? seconds. If that's on purpose, fine, but it looks weird.

In your "always" loop, you should only change the animation if it's necessary, so

if (Fired? == True and Animation For Self != Fired) {
  Switch animation to Fired for self;
}

if (Fired? = False and Animation For Self != Idle) {
  Switch animation to Idle for self;
}



In the pressure plate behavior, you are using "self" in the "get" blocks. So, you are getting _UniqueID and _IsActive from the Actor the behavior is attached to, which I assume is a pressure plate. You need to use "Actor of Type" where you have Self. That way, as you cycle through all the Actors of type "Down Cannon," you are checking the current Down Cannon for the values.

You never use the Cannon List, instead you are checking "_UniqueID" against the value "Yes." Let me explain Cannon List.

Cannon list should be a list, with values like this:
0
2
3
5

Then, you check each Down Cannon's _UniqueID against each item in Cannon List. That way, one pressure plate can control multiple Down Cannons. So, your loop should look like this:

For each Actor of Type Down Cannon {
  For each item in Cannon List {
    If (for [actor of type], get [_UniqueID] from behavior [Cannon Fire] == item from Cannon List) {
      Do stuff;
    }
  }
}

Finally, you never set IsActive? back to true, so once the pressure plate is stepped on, the Down Cannon will always be off. At the end of the "always" loop in your Cannon Fire behavior, set "IsActive?" back to True. That way, the Cannon starts each frame with IsActive? being True, and it only gets turned off if the player is still on the pressure plate.

Uuemaich

  • Posts: 52
Alright, I'm not sure why you're using two timers in your first behavior. The way you have it, you're waiting for every Shoot seconds, then waiting again for Delay? seconds. If that's on purpose, fine, but it looks weird.

Oh, I have it set like that so I can control each cannon in the scene editor differently. So one cannons shoots every 2 seconds, and the next cannon shoots every 2 second but only after 1 second. So they shoot back and forth.

In your "always" loop, you should only change the animation if it's necessary, so

if (Fired? == True and Animation For Self != Fired) {
  Switch animation to Fired for self;
}

if (Fired? = False and Animation For Self != Idle) {
  Switch animation to Idle for self;
}

It's actually working how I have it now. The cannon is in idle, and when it fires it switches to it's fired animation, and then after 1 second (I changed it to 0.25), it switches back to idle.

In the pressure plate behavior, you are using "self" in the "get" blocks. So, you are getting _UniqueID and _IsActive from the Actor the behavior is attached to, which I assume is a pressure plate. You need to use "Actor of Type" where you have Self. That way, as you cycle through all the Actors of type "Down Cannon," you are checking the current Down Cannon for the values.

Sorry, I don't fully understand. I didn't realize I could drag the "Actor of Type" thingy down and into the "get" blocks. Is that what I'm supposed to do? XD

You never use the Cannon List, instead you are checking "_UniqueID" against the value "Yes." Let me explain Cannon List.

Cannon list should be a list, with values like this:
0
2
3
5

Then, you check each Down Cannon's _UniqueID against each item in Cannon List. That way, one pressure plate can control multiple Down Cannons. So, your loop should look like this:

For each Actor of Type Down Cannon {
  For each item in Cannon List {
    If (for [actor of type], get [_UniqueID] from behavior [Cannon Fire] == item from Cannon List) {
      Do stuff;
    }
  }
}

Again, sorry. This is the first time I've ever used a list so I don't fully understand. For "item from Cannon List", do I just type in the number or text in the list that I'm looking for, or is there a block I need to pull out? In the list I added values "Yes" and "No" and then in the Unique ID's for the cannons I wanted the plate to control I put in Yes, and for the ones I don't want it to control I put in No.

Finally, you never set IsActive? back to true, so once the pressure plate is stepped on, the Down Cannon will always be off. At the end of the "always" loop in your Cannon Fire behavior, set "IsActive?" back to True. That way, the Cannon starts each frame with IsActive? being True, and it only gets turned off if the player is still on the pressure plate.

I did that because I didn't want the cannons to come back on.

Thanks again, you're awesome!

Nomosoft

  • Posts: 122
In your "always" loop, you should only change the animation if it's necessary, so

if (Fired? == True and Animation For Self != Fired) {
  Switch animation to Fired for self;
}

if (Fired? = False and Animation For Self != Idle) {
  Switch animation to Idle for self;
}

It's actually working how I have it now. The cannon is in idle, and when it fires it switches to it's fired animation, and then after 1 second (I changed it to 0.25), it switches back to idle.

Oh, it'll work the way you've got it, but changing an animation every frame when it isn't necessary is wasteful. A simple "if" check takes basically no time at all, whereas the mchanics of switching the animation probably has a more significant overhead. I'm not sure how Stencyl/Flixel handles that under the hood, but it's certain to be more costly than an "if" statement.

In the pressure plate behavior, you are using "self" in the "get" blocks. So, you are getting _UniqueID and _IsActive from the Actor the behavior is attached to, which I assume is a pressure plate. You need to use "Actor of Type" where you have Self. That way, as you cycle through all the Actors of type "Down Cannon," you are checking the current Down Cannon for the values.

Sorry, I don't fully understand. I didn't realize I could drag the "Actor of Type" thingy down and into the "get" blocks. Is that what I'm supposed to do? XD

Yes, that's correct.  The Actor in the "Self" box is the Actor that block is talking to. If you leave it on Self, it is talking to the Actor the behavior is attached to. If you drag a reference to another Actor into there, the block will talk to that Actor, instead of to Self.

You never use the Cannon List, instead you are checking "_UniqueID" against the value "Yes." Let me explain Cannon List.

Cannon list should be a list, with values like this:
0
2
3
5

Then, you check each Down Cannon's _UniqueID against each item in Cannon List. That way, one pressure plate can control multiple Down Cannons. So, your loop should look like this:

For each Actor of Type Down Cannon {
  For each item in Cannon List {
    If (for [actor of type], get [_UniqueID] from behavior [Cannon Fire] == item from Cannon List) {
      Do stuff;
    }
  }
}

Again, sorry. This is the first time I've ever used a list so I don't fully understand. For "item from Cannon List", do I just type in the number or text in the list that I'm looking for, or is there a block I need to pull out? In the list I added values "Yes" and "No" and then in the Unique ID's for the cannons I wanted the plate to control I put in Yes, and for the ones I don't want it to control I put in No.

If you're only going to have two options - Yes and No - you don't need the list at all, you just check "if Unique ID == Yes." The point of the Cannon List is to let each pressure plate control an arbitrary number of Down Cannons.

Pretend you have four Down Cannons and two pressure plates. The Down Cannons have these Unique IDs:
Down Cannon 1 = 0
Down Cannon 2 = 1
Down Cannon 3 = 2
Down Cannon 4 = 3

Pressure Plate 1 has a Cannon list of:
0
2

Pressure Plate 2 has a Cannon List of:
1
3

Now, each Pressure Plate does this:

For each Down Cannon in the scene {
  For each item in Cannon List {
    If (Unique ID of Down Cannon == item from Cannon List) {
      Turn off current Down Cannon;
  }
}

So, each Pressure Plate goes through each Down Cannon in the Scene, checking to see if that Down Cannon's Unique ID is in its Cannon List. If it is, it turns off that Down Cannon. To make this comparison, you check the Down Cannon's Unique ID against each item in the Cannon List.

If (Unique ID == current item from Cannon List) { }

Uuemaich

  • Posts: 52
Oh, it'll work the way you've got it, but changing an animation every frame when it isn't necessary is wasteful. A simple "if" check takes basically no time at all, whereas the mchanics of switching the animation probably has a more significant overhead. I'm not sure how Stencyl/Flixel handles that under the hood, but it's certain to be more costly than an "if" statement.

Okay then, I'll do that! I didn't know it was wasteful or anything. :)

Yes, that's correct.  The Actor in the "Self" box is the Actor that block is talking to. If you leave it on Self, it is talking to the Actor the behavior is attached to. If you drag a reference to another Actor into there, the block will talk to that Actor, instead of to Self.

Awesome. Thanks a lot!

If you're only going to have two options - Yes and No - you don't need the list at all, you just check "if Unique ID == Yes." The point of the Cannon List is to let each pressure plate control an arbitrary number of Down Cannons.

Pretend you have four Down Cannons and two pressure plates. The Down Cannons have these Unique IDs:
Down Cannon 1 = 0
Down Cannon 2 = 1
Down Cannon 3 = 2
Down Cannon 4 = 3

Pressure Plate 1 has a Cannon list of:
0
2

Pressure Plate 2 has a Cannon List of:
1
3

Now, each Pressure Plate does this:

For each Down Cannon in the scene {
  For each item in Cannon List {
    If (Unique ID of Down Cannon == item from Cannon List) {
      Turn off current Down Cannon;
  }
}

So, each Pressure Plate goes through each Down Cannon in the Scene, checking to see if that Down Cannon's Unique ID is in its Cannon List. If it is, it turns off that Down Cannon. To make this comparison, you check the Down Cannon's Unique ID against each item in the Cannon List.

If (Unique ID == current item from Cannon List) { }

Oh okay, I think I understand now!

Well, it's now working exactly how I need it to, and there's no way to properly thank you for all of the help. But thank you very much. You're an incredible person. :)
 

Nomosoft

  • Posts: 122
You're welcome, good luck with your game.