Check if Player Coord. equal Follower Coord. via Conditional Branch Script Call

DracoDelphoi

Warper
Member
Joined
Jun 2, 2020
Messages
3
Reaction score
0
First Language
German
Primarily Uses
RMMV
I try to create a 'Snake' minigame and need to check if the Player Coordinates are equal to the Coordinates of my followers (to check if i 'bite' myself).

I would like to achieve this with a Conditional Branch script or something else, to execute an action whenever a conditional branch for X and Y coordinates match. I know that i could check the follower and Player coordinates after every step with the Map X of Player and $gamePlayer._followers.follower(0).x, store everything in variables and compare them, but that would be too much work, especially if i had 10+ 'Body parts' (followers). I use HIME_GuestFollowers Plugin to be able to have more than 4 followers.

If you have an even easier solution, I would love to hear it :)
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
3,282
Reaction score
4,407
First Language
English
Primarily Uses
RMMV

I've moved this thread to RPG Maker MV. Please be sure to post your threads in the correct forum next time. Thank you.

 

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,364
Reaction score
614
First Language
Portuguese - Br
Primarily Uses
RMMV
Hi!
Assuming that Hime adds the followers with the default code, you can use that in a script call:

JavaScript:
const followers = $gamePlayer._followers._data;
let l = followers.length;
if(!l > 0) return;
while(l--){
    if($gamePlayer._x === followers[l]._x && $gamePlayer._y === followers[l]._y){
        //do something.
        break; // you can use this word optionally if you want to interrupt the check after find one match.
    }
}
If the player has one or more followers, it will check the player's position with all the followers he has.
If one matches with the same position, you do your code.
 

DracoDelphoi

Warper
Member
Joined
Jun 2, 2020
Messages
3
Reaction score
0
First Language
German
Primarily Uses
RMMV
Hi!
Assuming that Hime adds the followers with the default code, you can use that in a script call:

JavaScript:
const followers = $gamePlayer._followers._data;
let l = followers.length;
if(!l > 0) return;
while(l--){
    if($gamePlayer._x === followers[l]._x && $gamePlayer._y === followers[l]._y){
        //do something.
        break; // you can use this word optionally if you want to interrupt the check after find one match.
    }
}
If the player has one or more followers, it will check the player's position with all the followers he has.
If one matches with the same position, you do your code.

Thank you for your reply ^^ but your Code sadly didn't work (SyntaxError Illegal return statement), maybe i'm just too dumb to use it, i'm completely new to programming, but i got something to work with the following:

JavaScript:
if ($gamePlayer.x === $gamePlayer.followers().follower(index).x && $gamePlayer.y === $gamePlayer.followers().follower(index).y) {//do something}
But it only works with the first 4 Guest Followers from HIME_GuestFollowers Plugin...
So is there any way that this can interact with the other Guest-Followers? Maybe a different Plugin that i wasn't able to find?
 

Eliaquim

Raze: The Rakuen Zero's Guardian!
Veteran
Joined
May 22, 2018
Messages
1,364
Reaction score
614
First Language
Portuguese - Br
Primarily Uses
RMMV
Maybe try to replace that part
if(!l >0) return;
With this one.
if(!l >0){return false};
If it didnt work, I will try tomorrow again.
 

DracoDelphoi

Warper
Member
Joined
Jun 2, 2020
Messages
3
Reaction score
0
First Language
German
Primarily Uses
RMMV
Maybe try to replace that part
if(!l >0) return;
With this one.
if(!l >0){return false};
If it didnt work, I will try tomorrow again.

Got the exact same Problem :/ the Code for testing looks like this (set Player transparent only to see if it works),
maybe there are some mistakes that i made because i dont now what i'm doing xD:

JavaScript:
const followers = $gamePlayer._followers._data;
let l = followers.length;
if(!l >0){return false};
while(l--){
    if($gamePlayer._x === followers[l]._x && $gamePlayer._y === followers[l]._y){
        $gamePlayer.setTransparent(true)
    }
}
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Profile Posts

lunarrosecrow wrote on hiddenone's profile.
please don't lurk hiddenone I'm quarantining!!!
lunarrosecrow wrote on Edward.T's profile.
Hello Edward sorry to bother you and didn't start a conversation cause I thought i'd be a little weird or disrespectful but I was wondering do you still have your Generator resources you posted as the links on the page are dead?
Stream will be live shortly! It is my birthday, and thus I am doing an extended stream! I will be doing a variety of things. Among the activities I will be doing: Playing Oceanhorn: Monster of the Uncharted Seas, art, and some Text Adventure~ Feel free to drop by!
It would be cool if you could "copy as code" event commands :< .
Just managed to recover my Yahoo e-mail that i lost 3 months ago. Turns out an IP from U.S had hacked it and set the pass back to normal.. Like WTF ?

Forum statistics

Threads
99,485
Messages
965,925
Members
131,112
Latest member
Reji
Top