Conditional Branches

Eni

Demon Lord
Veteran
Joined
Oct 30, 2018
Messages
48
Reaction score
5
First Language
Swedish
Primarily Uses
RMMV
So what I need here is more else if statements.
So first I'll be checking the value of two variables and if any of them does not match it will check the value of two other variables.
Did that make sense? Prolly not but the idea is I want to have more than 2 conditions. like 10 but I have no idea on how to do that.

Screenshot_1.png

Now I just looked this up and found out this is about how the code should work to check if one statement is true.

To clarify what I'm doing right now is. Might fighter Exp will go up by +5 Exp each time I use specific skills. Once that value reaches 100 or more it will check if my fighter level is still lvl 1. if yes it will increase to level 2.
No in the event that the fighter level is already lvl 2 and needs to go up to lvl 3 I can do in the Else branch but what if I want a to advance to lvl 4 and 5 and so on. Keep in mind that this check will have to run each time I use a "Fighter skill" and the other Common events will have to do something similar too.

Feels like a lot of unecessary work(I fear that it might lag more than it needs too) if I created several lone if statements which would cause the program to look though the other 9 or so if statements this event has even though say the third one already was true and there was no need to look further.

So to the main question is is there a way to use "else if" statements? If not are there other alternatives?

Edit: Also I don't know javascript so if someone could comfirm if the check I posted was correct and will do the thing I want or if I have something way wrong and off target :p
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
29,244
Reaction score
6,784
First Language
German
Primarily Uses
RMMV
you don't need ,more branches, you need to learn two alternative techniques to handle things.

the first is that you can nest conditional branches - place another conditional branch into the true branch and both branches need to be true to process the inner true segment.

the second is sorting variables for checks. if a single variable is to be checked for a series of values, you just have to use the correct sorting and then you can use one conditional branch for each segment, even disabling the entire else branch for better readability.
 

Eni

Demon Lord
Veteran
Joined
Oct 30, 2018
Messages
48
Reaction score
5
First Language
Swedish
Primarily Uses
RMMV
I understand the first option but how do you mean with the second one? Sounds like one really long check xD
Could you provide one example?
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
300
Reaction score
1,150
First Language
Bahasa
Primarily Uses
RMMV
Let me get this straight...
So you want to manually create experience curve, and you think the best way to do it is by having "else if" statement to be possible?

Here's an alternative...
It's better if you know arithmethic. But if you prefer manual input, first you start of by making an array for the experience curve. Each value in the array is the requirement experience to attain next level. It also work to determine max level. Then you only need to check it in a single execution.
1579962006672.png

From my example, the outer condition is a check so that you won't gain experience when you reach max level which is 9 (the length of the array). The inner condition is a dynamic check corresponding to your current level. You may try it yourself if my solution suit your need.
 
Last edited:

BalticoX

Villager
Member
Joined
Jul 22, 2019
Messages
12
Reaction score
3
First Language
English
Primarily Uses
RMMV
Kuro solution is elegant. Also the first option Andar suggested, which is nested “If” inside other “if” or inside the “else” depending on what you need. By sorting, Andar means that you can nest the conditions in a way that you do the minimum validations needed. But Kuro’s looks simpler.

The other option is to learn JavaScript to do simple things and in there you can use AND (&&) and OR (||) and “else if”, even switch / case

but since that will take you some time, use proposed methods.

don’t fear lag, it is ok to have “if” commands running on many events, it’s even ok to have if commands run on every frame. I do that all the time to check if the character is on certain zone to trigger events, and it works perfectly. What is not ok is to put loops inside events that run every frame. But that is not your case, so go with nested conditions.
 
Last edited:

Eni

Demon Lord
Veteran
Joined
Oct 30, 2018
Messages
48
Reaction score
5
First Language
Swedish
Primarily Uses
RMMV
Hmm.. that does look useful!

But what if I wanted skills to be added with the levels? like level 2 and you gain "Power strike skill" and lvl 3 "Something else skill"? I don't see an opening to sneak that in?
 

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
300
Reaction score
1,150
First Language
Bahasa
Primarily Uses
RMMV
1579966029810.png

Since it only happen when you "level up", and you only deal with single variable, you don't need to use the "else". Hence making your event much organized.
 

Eni

Demon Lord
Veteran
Joined
Oct 30, 2018
Messages
48
Reaction score
5
First Language
Swedish
Primarily Uses
RMMV
Thanks! I'll give this a try and see how this goes!

Um just one more question... How do I set up the array?

Edit: Nvm I think I figured it out. but just to make sure can the same array be used for all the other classes or do I have to make a new one?
 
Last edited:

Kuro DCupu

Trust me, I'm a veteran RMer
Veteran
Joined
Jul 6, 2014
Messages
300
Reaction score
1,150
First Language
Bahasa
Primarily Uses
RMMV
1579967408375.png

You write each value inside a square bracket
 

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

Latest Threads

Latest Posts

Latest Profile Posts

Hope everyone is enjoying their weekend!!!
Now irinea just blocked me in discord
Just finished making a character selector at the beginning of the game that allows the player to pick gender and skin tone. I couldn't be more pleased.
Stream will be live shortly with some Witcher 3! Feel free to drop by!
Helldivers is so much fun!

Forum statistics

Threads
94,616
Messages
922,393
Members
124,499
Latest member
GameDev64
Top