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

Couple hours of work. Might use in my game as a secret find or something. Not sure. Fancy though no? :D
Holy stink, where have I been? Well, I started my temporary job this week. So less time to spend on game design... :(
Cartoonier cloud cover that better fits the art style, as well as (slightly) improved blending/fading... fading clouds when there are larger patterns is still somewhat abrupt for some reason.
Do you Find Tilesetting or Looking for Tilesets/Plugins more fun? Personally I like making my tileset for my Game (Cretaceous Park TM) xD
How many parameters is 'too many'??

Forum statistics

Threads
105,865
Messages
1,017,059
Members
137,574
Latest member
nikisknight
Top