Detect if actor exited region, from list of regions

ariakbari

  • *
  • Posts: 43
Hello,

In my game, at the start I am creating several regions and adding each to a list, "list1". Using the blocks shown in the attachment, I am able to successfully create things in each region once the actor enters that specific region. Perfect so far.

Now, when my actor enters each region and I create some things, I want to be able to kill these things being created from the region the actor was just in ("item"), once he exits that region. Doesn't seem too sophisticated, but I'm new-ish to lists and not sure how to go about this, as there is only an "if actor is inside region" block and nothing of the sorts for an exit block...

There is the event you can create "if actor exits region" but I wouldn't be able to call on a list from there I don't believe. Doing one of these for each region would not be useful, as I have tons of regions. Simply using "not (actor is inside region)" does not work either, as this just cancels all actions all together and doesn't allow my actor to create anything. Lastly, I tried doing an if statement for my actor exiting each side of the region, "if (x of actor) > x of (item)" "if (y of actor) > y of (item)" etc. but that also cancelled out my actions being performed in the first place. I didn't figure either of these would be the way to go about it as I could see how they would screw things up, but I figured it was worth a shot. No luck so far.

So basically- Any good way for me to kill everything I just created in a region upon exiting that region, while using "for each"?

I would be happy to post more of my code if that helps. I'm also glad to go into further detail if needed. Any help is appreciated. Thanks!

« Last Edit: October 17, 2018, 08:29:13 pm by ariakbari »

merrak

  • *
  • Posts: 2259
One thing you could do is store the region the actor is created in as an actor value. When the player exits a region, loop through all of the actors and kill the ones which are flagged as belonging to the stored region.

ariakbari

  • *
  • Posts: 43
One thing you could do is store the region the actor is created in as an actor value. When the player exits a region, loop through all of the actors and kill the ones which are flagged as belonging to the stored region.

Thanks for the reply. I'm not 100% sure I follow you here. So store the region (current "item" the actor is in) as an actor attribute?

Then which blocks shall I use for when the player exits a region? The "when player exits region event" and set one for each region ? Seems like the only option but I would have to make quite a few to account for every region... not sure this is what you mean.

I think I'm just missing you entirely... I've read what you said a couple times and am not sure how to execute that. If you have a chance to clarify my confusion I'd love to hear and hopefully get this worked out. Thanks

« Last Edit: October 17, 2018, 10:30:09 pm by ariakbari »

merrak

  • *
  • Posts: 2259
If I could see more of your code then I could better explain how you might integrate my idea with what you currently have. There are several ways to accomplish this, but I bet there's one way that would minimize how much of your current code you'd have to rework.

ariakbari

  • *
  • Posts: 43
If I could see more of your code then I could better explain how you might integrate my idea with what you currently have. There are several ways to accomplish this, but I bet there's one way that would minimize how much of your current code you'd have to rework.

Attached. Let me know if more is needed, this should be sufficient.

1st screenshot is in updating event. "Pre Point" is the angle my character is facing. I find the pre point values for 4 sets of angles, in hand one actor (wall) created for each set. You can see the second set of angles with 45 and -45 at the Bottom.  I only ever have one of the walls active at a time. This happens in each region.

As you can see, when of these 4  "pre point" values become true, aka my actor facing one of 4 ways, I kill all other walls (so I am keeping one active always) and create one the direction I'm facing.  So if I'm facing up, I have a wall above me, I spin 90 degrees clockwise, that wall is killed and now I have one to my right. All this works great.

But if I am in one of my regions, facing upwards let's say, and exit the region, still facing up, since I didn't change my direction the wall is not killed. For this reason, I need to be able to kill these actors when I exit the region.

I also attached some of the regions being made and added to my list in my created event.

merrak

  • *
  • Posts: 2259
I think I see what's going on now. I was imagining a different scenario, but you want to kill the walls when the WhiteBall4 leaves a region?

One thing you can do is set up a behavior, attached to the ball, that contains two attributes: "Current Region" and "Current Region Temp"

In an "always" event, set up the following code

Code: [Select]
On Update:
    set Current Region to Current Region Temp
    set Current Region Temp to the region the ball is in
    check the state of the two booleans and react accordingly

There are two states you'll want to check for and write code to react to:

Current Region == Current Region Temp: The ball has not moved from one region to another

Current Region =/= Current Region Temp: The ball has moved. Current Region will be the region the ball is moving out of, and Current Region Temp will be the region the ball is moving into. This state will only be held for one engine step and so will execute only once each time the ball changes regions.

ariakbari

  • *
  • Posts: 43
I think I see what's going on now. I was imagining a different scenario, but you want to kill the walls when the WhiteBall4 leaves a region?

One thing you can do is set up a behavior, attached to the ball, that contains two attributes: "Current Region" and "Current Region Temp"

In an "always" event, set up the following code

Code: [Select]
On Update:
    set Current Region to Current Region Temp
    set Current Region Temp to the region the ball is in
    check the state of the two booleans and react accordingly

There are two states you'll want to check for and write code to react to:

Current Region == Current Region Temp: The ball has not moved from one region to another

Current Region =/= Current Region Temp: The ball has moved. Current Region will be the region the ball is moving out of, and Current Region Temp will be the region the ball is moving into. This state will only be held for one engine step and so will execute only once each time the ball changes regions.

Awesome. For now I went ahead and just put the code in the "if WhiteBall4 is inside item" bracket so I could easily reference my list in that scene. I wasn't sure how to reference my local attribute list from the scene in the actor behavior...

Regardless, where I have it it's working great so far. Only issue I notice is if my player comes to a stop and he is overlapping two regions, no walls are created around me. In my "created" code you can see the positions of my regions, so for example if my actor's x-center is 150, he is in two regions, overlapping... When he is like this, in two at a time, none of my walls are created. Not sure if this attributed to placing the code where I did as opposed to as a behavior. Let me know if there is a fix. Besides that it's working flawless. Thanks a ton for the help.