Outer Inner Switch with a variable X, Y

So I'm trying to create an event that when moved onto another event it will trigger that events inner switch.

In a more understandable way, I'm having the main character throw a boulder and if it lands on a monster then the monsters self switch ('D' for dead) activates.

This is the script I have so far:
$gameSelfSwitches.setValue(
[$gameMap._mapId,
$gameMap.eventIdXy(

$gameVariables.value(98),
$gameVariables.value(99)
),
​
'D'],
true);


The code works when I call it before I move the boulder event, but doesn't work after I move the boulder. This is a little problematic because I don't want the monster to be squished BEFORE the boulder hit it.

I think the problem is that when I call $gameMap.eventIdXy() it returns the TOP event, which would be the boulder. It might return an array of the events that occupy that space, though I think it's the former because I tried treating it like an array and it changed nothing. =(

Does anyone know of any potential workarounds or a simpler solution?

Here is the reference for the function calls (from the docs):
var key = [mapId, eventId, A-D]
$gameSelfSwitches.setValue(key, true);
Instead of getting the event ID from the x,y, cant you just supply the ID youself? Given this will only be possible if there is only one monster in that map.

You could also possibly make an array of the ID of all monster events, then check which monster event has a current X,Y that is the same as the boulder.
If it works before moving the boulder and not after moving it, then the issue is not with your script call, but with your event itself. It may be that your boulder event isn't set to through, so it actually can't move onto the monster. It may be that you don't have a 'wait for completion' on the move route. It may be other reasons.

Please show a screenshot of the event that calls the above script, so we can see what else you're doing there. Include the full event window - don't just crop it to the event commands, because there's important stuff elsewhere on the page.

Does the boulder actually move onto the event?

How are you populating variables 98 and 99? Don't answer that if it's shown in the screenshot.
@Shaz Alright, hopefully these can help.

upload_2019-2-28_4-37-26.png


The if: Script: $gameMap.regionId($gameVariables.value(98), $gameVariables.value(99)) === 200 || $gameMap.regionId($gameVariables.value(98), $gameVariables.value(99)) === 201; is for checking to see if the next push will hit a wall. If it does it will reverse the movement, this way the boulder will never get stuck.

upload_2019-2-28_4-38-22.png


Normal monster state.

upload_2019-2-28_4-41-44.png


Dead monster state (using a very different down state so it's very visible when states change.)

upload_2019-2-28_4-42-39.png




upload_2019-2-28_4-43-54.png


The boulder does fall on top of the monster

upload_2019-2-28_4-44-32.png


Alive?

upload_2019-2-28_4-45-28.png


Now an example of it working

Setting the forced self switch BEFORE the boulder moves
upload_2019-2-28_4-47-41.png


upload_2019-2-28_4-48-53.png


We can already tell it worked

upload_2019-2-28_4-49-34.png


upload_2019-2-28_4-50-11.png


I think it's just reading the topmost event, so when the boulder moves, it becomes the topmost event.

I did think of a workaround that I'm not fond of. We can play musical self switches. Have the boulder hit self switch C, then make it wait about 15 frames, then have it switch to D. This works, but it's pretty inelegant, so I'm still open to ideas.
@Engr. Adiktuzmiko The map is going to get pretty big and I'm probably going to be deleting monsters and adding them back in and moving them, etc. Keeping track of them all by hand will be busywork that I really want to shave off by having the event care about it so I don't have to. =/

If it were a smaller map with a manageable amount of enemies that would definitely be a good solution.
I'd remove the script for the region id, and just set another variable using Get Location Info (on the 3rd tab of event commands). Then you can do the test to see if the new variable (the region of the destination point) is one of the ones you're interested in (this is for checking the wall).

For the movement route, you can get rid of $gameMap.event(this._eventId) from that script, and replace it with this. Because this is the event the move route is being performed on, and is exactly the same as what $gameMap.event(this._eventId) will give you. So it'll end up
Script: this.jumpToPoint($gameVariables ... etc


But none of that has anything to do with your original issue. Here's what's going on ...

If you throw the boulder onto a tile where a monster is, before you throw the boulder, there is only one event there - the monster; after you throw the boulder, there are two events there - the monster, and the boulder. $gameMap.eventIdXy(x, y) returns the event with the lowest event number! Your boulder event is 39, and your monster event is 45. So it's going to return the event id of your boulder event rather than the monster event. And that's the event whose self switch you're turning on. Because you don't have a page on your boulder event conditioned by self switch D, it looks like nothing happened (for fun, add a second page to that event with a different sprite, and set its condition to self switch D, then run the test and see that you are, in fact, adjusting the self switch on the boulder event).

If you throw the boulder onto a tile where there's no monster, before you throw it, there are no events there, so $gameMap.eventIdXy(x, y) will return 0. So you're turning on a self switch for event 0, which doesn't exist. After you throw the boulder, again, the only event at that location is the boulder itself, and we've already gone over that.

It's much better to get the event id into a variable before you throw the boulder. Then throw the boulder, and IF there's an event there (that variable is not 0), then change the self switch, using the variable that already contains the event id, rather than checking at that time to see what event(s) might be there.

It'll look something like this:

Code:
(set your 98 and 99 variables as necessary)
Get Location Info: Event ID into variable 100 using variables 98 and 99 for the location
Set Movement Route: This Event: Speed 3, Script: this.jumpToPoint(var 98, var 99)
Wait 7 Frames
Conditional Branch: Variable 100 (event at destination) > 0
  Script: $gameSelfSwitches.setValue([$gameMap._mapId, $gameVariables.value(100), 'D'], true)
End

So you're getting the event id when there's a maximum of one event on that location, and then you're using the stored event id, rather than trying to find out what the event id is when there could be 2 events there.
@Shaz I had no idea Get Location Info existed, thanks for the tip! That'll definitely help cut down on event lines.

So I the way I did it now with your suggestions actually works out better. So if there is a squishable event where the boulder would be, I grab it first and have it switch it's Self Switch to C. This is helpful because I can set the movement to Fixed to prevent the event from moving while the boulder is moving. Then I just have it wait a few frames and switch over to D using Parallel processing.

and I did do the fun test:

upload_2019-2-28_23-59-28.png


Throw a boulder, get a boat!
No, don't use a parallel process. If the movement is fixed, it'll stop moving as soon as you turn on self switch C. Keep the change to self switch D in the boulder event as well. There's no need to move that onto the monster event. It can turn on both self switches with a wait in between.

Nice test btw 😉
@Shaz You're right! Because I already have the event's ID. I did an autopilot design there.
The goal is to avoid parallel processes where possible, and to avoid distributing logic for a sequential process between events, using conditions to trigger them at certain times. Neither of these are bad things, but they're opportunities for issues to present themselves and a lot of people struggle with troubleshooting when weird things happen.

As soon as you start adding parallel processes, you have to be careful about how they're designed if you don't want to cause lag, and as soon as you distribute processing between multiple events (turning on switches/self switches with the boulder event that controls things that happen on other events) you have to be careful about coordination and keeping things in sync. It's just easier to keep all the logic in a single place.

Try and do that with everything, and only look at those options when you just can't get it working that way (but maybe come here first as we might be able to see a way that you're missing) 🙂

Original thread: https://forums.rpgmakerweb.com/threads/outer-inner-switch-with-a-variable-x-y.106182/