Check if an event tile 2 steps infront of the player is passable or not

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,675
Reaction score
11,194
First Language
English
Primarily Uses
RMMV
The code from the screenshot is from other stuff I've tested before. It checked the direction of the Event whose passability I wanted to check. This event always faces right if any self-switch is on so that's why it has this conditional. Sorry for being confusing here.
The logic is still wrong.

You started this thread saying you wanted to check the tile 2 steps in front of the player.

If what you actually want is what you described in Post #7, where it is always simply checking the tile to the left of the event, then I don't know why you're going off of anything to do with the player. The player's x, y, and direction has nothing to do with it.

Code:
$gamePlayer.canPass(this.x, this.y, 4)

Good luck with your project!
 

dfGen21

Regular
Regular
Joined
Nov 16, 2020
Messages
32
Reaction score
2
First Language
English
Primarily Uses
RMMZ
The logic is still wrong.

You started this thread saying you wanted to check the tile 2 steps in front of the player.

If what you actually want is what you described in Post #7, where it is always simply checking the tile to the left of the event, then I don't know why you're going off of anything to do with the player. The player's x, y, and direction has nothing to do with it.
The first code of the screenshot is not related to this thread or anything mentioned here. It's just one of many things I tried. It uses a different logic. I checked the direction of the target event. Just noticed a bug inside my screenshot: This first conditional should check only one direction and not both.

The logic for this was this:
I went the player direction route cause each event can be triggered by 2 sides. The event from the screenshot the Player has to be facing either right or left. I started eventing without considering interactions with other events but I kept the Player direction logic and used it for following extra stuff. This thread here is based on the extra stuff.

Just explaining my thought flow making this puzzle. Wasn't fully planned ahead. I used my limited knowledge and bypassed errors somehow until it works. I also tend to keep weird code and correct it with instead of redoing it. At least that's what I do until I know how make it work fully. Right now the puzzle is being remade with your help. Most things you tell me here weren't even known by me and that's why my logic is inconvenient to replicate the effect of what you would do. Maybe I should include an explanation like this everytime to minimize misunderstandings. Think that can happen easily with me.

Code:
$gamePlayer.canPass(this.x, this.y, 4)
So this one checks the left tile next to the event right? It should be the equivalent of
$gamePlayer.canPass($gamePlayer.x-1, $gamePlayer.y, 4) cause it uses the event as starting point instead of the Player? I tried it out but it doesn't work like the gamePlayer version aka the condition doesn't get triggered. Did I miss a step or made other mistake? Does "this" have to be defined somehow cause that's the only difference. Using the coordinates of the event instead of this.x/y makes it work.
 

AmVa

Regular
Regular
Joined
Jul 6, 2022
Messages
123
Reaction score
44
First Language
English
Primarily Uses
RMMV
$gamePlayer.canPass(this.x, this.y, 4)
this isn't going work in a script call, because "this" refers to the game interpreter, neither the event nor the player.

$gamePlayer.canPass($gamePlayer.x, $gamePlayer.y, $gamePlayer.direction()) checks if the player can pass if they move from their current position one step forward.

To check if the player can move 2 steps forwards regardless of the direction, you'd need a couple more lines of code:

Code:
var d = $gamePlayer.direction();
var x = $gamePlayer.x
var y = $gamePlayer.y
var x2 = $gameMap.roundXWithDirection(x, d);
var y2 = $gameMap.roundYWithDirection(y, d);
$gamePlayer.canPass(x, y, d) && $gamePlayer.canPass(x2, y2, d)

I'd recommend putting this in a small plugin as a new function if this is something your game uses a lot, it will make things a lot easier.

Anyhow, keep in mind that this script call doesn't check for an event's passability, it checks whether a character (in this case, the player), can pass from a given position in a given direction. it only checks 1 step at a time - if you want to check for bigger distances, it's more complex.
 

ATT_Turan

Forewarner of the Black Wind
Regular
Joined
Jul 2, 2014
Messages
12,675
Reaction score
11,194
First Language
English
Primarily Uses
RMMV
this isn't going work in a script call, because "this" refers to the game interpreter, neither the event nor the player.
Good catch! It would be
Code:
$gamePlayer.canPass($gameMap.event(this._eventId).x, $gameMap.event(this._eventId).y, 4)
 

dfGen21

Regular
Regular
Joined
Nov 16, 2020
Messages
32
Reaction score
2
First Language
English
Primarily Uses
RMMZ
Just tried out it this:

Code:
[5, 6, 8].forEach(event => {["A", "C", "D"].forEach(switch => $gameSelfSwitches.setValue([this._mapId, event, switch], false))})

[5, 6, 8].forEach(event => $gameSelfSwitches.setValue([this._mapId, event, "B"], true))

The second script works as expected but the first one gives me this error:

Code:
SyntaxError
Unexpected token 'switch'

Replacing switch with something else ignores this script with no effect if that's relevant. Tried my best to debug it.

Edit: Replacing switch was the solution but I did error somewhere else which causes wrong behaviour. Other than that thank you so much so far. Have to improve myself more to prevent asking like this too often.
 

Attachments

  • esdgsdfhgsdh.png
    esdgsdfhgsdh.png
    22.8 KB · Views: 4
Last edited:

Latest Threads

Latest Profile Posts

Me working on a deadline, "don't make the baseline and chords too funky, don't over compose it... remember, you have to finish it." Touches MIDI controller...instant funk.
TGA are coming up, and I'm still mad Lies of P didn't get nominated.
Like, they chose a remake of a 20 year old game and a vanilla 2D Mario game over it?

Bah, humbug!
I'll be there for the trailers and whatever weird mistakes are made.
I've bundled all my free plugin releases on itch.io I'll add more later, feel free to check it out! https://starlit.itch.io/rm-free-plugins
If I could draw, my Game Jam title screen would be a Krampus sitting in Santa's chair, his long, blonde hair flowing in the wind, sipping on an Espresso, while snacking on cheddar popcorn, chewing on an orange pencil pensively, while completing a crossword puzzle. I guess it's a good thing I can't draw.
Time for the next chance for y'all to affect my advent calendar! Where should Day 7's sprite come from: land, sea, or demon realm? :rwink:

Forum statistics

Threads
136,782
Messages
1,269,926
Members
180,534
Latest member
yuki7744111
Top