How can you use the OR in the conditional branch?

an_bit

Villager
Member
Joined
Jul 22, 2021
Messages
9
Reaction score
1
First Language
Vietnamese
Primarily Uses
RMMV
I want to make the player open their inventory and use their item to trigger an common event. But I want them to be able to use it from all 4 directions, so I tried to do it by using if and else, but only the position 15 12 works, when I used item on the other 3 positions, nothing happened. Is there anyway to use OR in rpg maker? Thank you.


or condition.pngcodes.png
 

Tea's Jams

I'm human
Global Mod
Joined
Mar 28, 2017
Messages
1,183
Reaction score
2,814
First Language
English
Primarily Uses
RMMZ
You have all the later conditionals nested in the first one, so only if the first one is true will the next one be run. You would make 4 different conditional statements, one for each direction. A script call would do it in one, I don't know what it would be off hand though.

**Ninja'd by @Pots Talos There's the script call :D
 

an_bit

Villager
Member
Joined
Jul 22, 2021
Messages
9
Reaction score
1
First Language
Vietnamese
Primarily Uses
RMMV
You have all the later conditionals nested in the first one, so only if the first one is true will the next one be run. You would make 4 different conditional statements, one for each direction. A script call would do it in one, I don't know what it would be off hand though.

**Ninja'd by @Pots Talos There's the script call :D

Ahhh I see, omg thats too long, guess Im gonna try to use script call.
 

an_bit

Villager
Member
Joined
Jul 22, 2021
Messages
9
Reaction score
1
First Language
Vietnamese
Primarily Uses
RMMV
You can use a script call in the conditional branch for this.
$gameVariables.value(1) == 15 || $gameVariables.value(1) == 13

The || is OR
Ah, I found it, thanks you very much. It works perfectly.
 

Pots Talos

Veteran
Veteran
Joined
Jun 28, 2012
Messages
175
Reaction score
173
First Language
English
Primarily Uses
RMMV
@minhanthongminh
You could also add AND (&&) into script call too.
So using your above screen shot I don't know what the variable number is for the X and Y so in this script I just used 1 for X and 2 for Y

($gameVariables.value(1) == 15 && $gameVariables.value(2) == 12) || ($gameVariables.value(1) == 13 && $gameVariables.value(2) == 12) || ($gameVariables.value(1) == 14 && $gameVariables.value(2) == 113) || ($gameVariables.value(1) == 14 && $gameVariables.value(2) == 11)

So its if player x is 15 and player y is 12 or if player x is 13 and player y is 12, ect, ect.
This way you can have all your checks in one conditional.
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
43,647
Reaction score
15,278
First Language
English
Primarily Uses
RMMV

@minhanthongminh , please avoid double posting, as it is against the forum rules. You can use the "Edit" function on your posts to add additional information you've forgotten or respond to multiple people. You can review our forum rules here. Thank you.



You can use the +Quote button to select multiple posts, then the Insert Quotes button to put them all into a single reply. Or just put @ followed by the person's name to tag them without actually quoting their entire post.

The above does not take the player's facing direction into account. So you could be standing on the tile below the event, facing any direction other than up, and use the item from your inventory, and it will work. Try it and see if that's what happens. Is that what you want?

If not, rather than testing where the player is standing, you can test what tile they're facing (where they would be standing if they took one step forward), and that will work no matter which tile they are standing on.

For this, you would do something like this:
Code:
Control Variables: Next X = Script: $gameMap.roundXWithDirection($gamePlayer.x, $gamePlayer.direction())
Control Variables: Next Y = Script: $gameMap.roundYWithDirection($gamePlayer.y, $gamePlayer.direction())
Conditional Branch: Next X = 14
  Conditional Branch: Next Y = 12
    ... whatever will happen if the player is standing on one of the 4 touching tiles, facing inward
  End
End
 

an_bit

Villager
Member
Joined
Jul 22, 2021
Messages
9
Reaction score
1
First Language
Vietnamese
Primarily Uses
RMMV
@Shaz Sorry, Im still new to this engine and forum, it should be like this right?

And your method works so much better, I didnt even think about that, thank you very much!
Also I dont understand the $gameMap.roundXWithDirection part, what does it do?
 
Last edited:

an_bit

Villager
Member
Joined
Jul 22, 2021
Messages
9
Reaction score
1
First Language
Vietnamese
Primarily Uses
RMMV
@Pots Talos Thank you! But I cant paste them all in one script box, I think its too small. Is there anyway to expand it?

@Pots Talos Ah my bad, I tried copy again and it works, idk why lol.
 
Last edited:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
43,647
Reaction score
15,278
First Language
English
Primarily Uses
RMMV
roundXWithDirection and roundYWithDirection take an x or a y coordinate and a direction, and returns the x or y coordinate that is one step in the specified direction from the original spot.

you also double posted again. Please reply to everyone in a single post, or edit your post and add the second reply, rather than posting twice in a row. You got the tagging right though ;)
 

Latest Threads

Latest Profile Posts

"I didn't know X song was about that!" Uh... why? Do you not listen to the lyrics? I mean, I guess that makes sense. We live in a world where nobody listens, but everyone wants to be heard.
Coding class: Python
Game dev work: Javascript
Result: AHHH!!! Writing program for an assignment and having it crash and burn because I used Javascript syntax or format. Or having my game die on me because of a python call :yswt:
Can we make it so whenever a banned user tries to use their account whilst banned, the forum should redirect to this
Anyone doing anything for NaNoWriMo this year?
Listening to, "Draum" by Eldrim. If you haven't heard it before, do so. Absolutely lovely, and utterly haunting.

Forum statistics

Threads
115,835
Messages
1,093,312
Members
151,025
Latest member
Mynastrus
Top