Script call conditional branch

Enderdude

Veteran
Veteran
Joined
Jun 21, 2015
Messages
52
Reaction score
11
First Language
English
Hello everyone of the rpg maker forums!.I'm having a little problem with the script call conditional branch. I'm trying to make a simple crafting system with script calls and i can't really figure out how to use the script call conditional branch. i'm not having any problems with the plugin i'm just having a bit of trouble understanding how you do it. Is it just like a if statement where you go  if (i brush my teeth){

                                                                                                                                                                                                                                                                                         then my teeth is clean

                                                                                                                                                                                                                                                                                   } 

would it be like that or something else i'm sorry if this thread makes almost no sense but i'm just needing a little help understanding it. thank you for reading  :guffaw:
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
It's called the 'if' condition.

You write it like this :

if(something){  // something happens}You also have 'else', when condition in 'if' is not met.

if(something){  // something happens}else{  // something else happens}And inbetween them you can have 'else if' 's, that are executed if 'if' 's conditions are not met, but their own conditions are:

if(something){  // executes when something is true}else if(somethingelse){ // executes when something is false, but somethingelse is true}else if(somethingthird){  // executes when something and something else are false, but somethingthird is true}else{  // executes when something, somethingelse and somethingthird are false.}In examples above, something, somethingelse and somethingthird are conditions.

Values of conditions can be true or false.

For example : 1 === 1 returns true, but 2 === 1 returns false, so you can write something like :

if(1 === 2){  // this obviously does not happen}else{  // this happens}Enough of that, what do you actually want to do?

What is that plugin?
 
Last edited by a moderator:

Enderdude

Veteran
Veteran
Joined
Jun 21, 2015
Messages
52
Reaction score
11
First Language
English
This is a great example. :guffaw: What I'm trying to do is use the script calls to make a simple crafting system like you got 2 choices you can craft a sword or a bow and this is where I needed to know how the if condition works. its gonna go like if you have the 2 items you needed it would remove the 2 you had and give you what you crafted. Its very simple.  :)  You could do this using events but I wanted to try to make a plugin of this for extra practice thank you for your time. 
 

Enderdude

Veteran
Veteran
Joined
Jun 21, 2015
Messages
52
Reaction score
11
First Language
English
I did some test and it works great thank you so much!
 

GaryCXJk

Veteran
Veteran
Joined
Dec 24, 2012
Messages
88
Reaction score
46
First Language
Dutch
Primarily Uses
Remember, when you are comparing just one variable with different values, it's better to work with switch-case blocks. Main advantage, you can break blocks whenever you want.

Code:
var testNum = function(num) {  var retVal = 0;  switch(num) {    case 0:      retVal = 1;      break;    case 1:    case 2:    default:      retVal = -1;      break;    case 3:      retVal = 2;    case 4:      retVal++;      break;  }  return retVal;}
In this case, using 0 will return 1, using 3 will return 3, using 4 will return 1 and using anything else will return -1.
 

KockaAdmiralac

Cube-shaped garbage can
Veteran
Joined
Jun 15, 2015
Messages
569
Reaction score
153
First Language
Serbian
Primarily Uses
N/A
And you can also use sign ?: operator.

For example, if you do this :

var a = (1 === 1) ? 2 : 3;a will be set to 2. But if for some reasons 1 isn't equal to 1 then it'll be set to 3.It's just a short way...
 

Enderdude

Veteran
Veteran
Joined
Jun 21, 2015
Messages
52
Reaction score
11
First Language
English
alright thanks this is very helpful.  :guffaw:
 

DarknessFalls

Rpg Maker Jesus - JS Dev.
Veteran
Joined
Jun 7, 2013
Messages
1,393
Reaction score
210
First Language
English
I would just create a function that evaluates to true or false and then use that function in the conditional branch of the event ... 
 

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

Latest Threads

Latest Posts

Latest Profile Posts

While we prepare the official trailer, enjoy this kind-of-second teaser! ^^
-Ele
New Episodes of RPG Shenanigans Uploaded to Youtube!

Episode 5 - Surprise Party!
Youtube Link:
Episode 6 - Killer Gin
Youtube Link:
Episode 7 - Gaia's Melody: Echoed Melodies
(Coming soon!)

Episode 8 - Clarent Saga: Tactics
(Coming soon!)

Episode 9 - Star Shift
(Coming soon!)
When the Map Generator throws in the assets in the most dumbest way possible - your path is blocked :D

I went to sleep at 3 am because of my anxiety. Set up my alarm for 7 am so that I could have sasagues for breakfast and do morning routine before lessons starts at 8 am. I knew I wouldn't be able to sleep even after my lessons finished because I have to visit my grandparents today I was sad bc I was really tired. Thats when I realised. My lesson starts at 9 am. I could get one extra hour of sleep if I didnt forget it

Forum statistics

Threads
107,563
Messages
1,030,578
Members
139,671
Latest member
WDRS
Top