Indie Dev

Hello Guest!. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, sell your games, upload content, as well as connect with other members through your own private inbox!

Help with Scripting a Conditional Branch

Status
Not open for further replies.

Trumully

Cyborg Kiwi
Hello!

I am trying to create a conditional branch in RPG Maker using scripting that checks if a character's MP is at 0 and then gives the player a game over.

I have tried looking for other alternatives to work around scripting but I couldn't find anything.

If anyone can help me with the scripting or finding an alternative way, that would be awesome!
 
A conditional branch in scripting, javascript, is called an if statement. See the below link from W3 on if statements in javascript.
http://www.w3schools.com/js/js_if_else.asp
and you could do with this one too:
http://www.w3schools.com/js/js_comparisons.asp

Now to in particularly do what you're asking this is the if statement you require:
JavaScript:
if($gameActors._data[1].mp == 0){
//Do some code
}
Now this only works if at some point during the entire game the character was apart of the party however if they haven't been then their magic hasn't been reduced. Change the number: $gameActors._data[1].mp, to the character actor Id found in the database.
 

Trumully

Cyborg Kiwi
A conditional branch in scripting, javascript, is called an if statement. See the below link from W3 on if statements in javascript.
http://www.w3schools.com/js/js_if_else.asp
and you could do with this one too:
http://www.w3schools.com/js/js_comparisons.asp

Now to in particularly do what you're asking this is the if statement you require:
JavaScript:
if($gameActors._data[1].mp == 0){
//Do some code
}
Now this only works if at some point during the entire game the character was apart of the party however if they haven't been then their magic hasn't been reduced. Change the number: $gameActors._data[1].mp, to the character actor Id found in the database.
Thanks dude! I forgot to mention I can do conditional branches with Java, but didn't know the right script call! Thank you!
 
Anytime as a note if you look in [Your game folder]/js/rpg_managers,js and look at the top you'll find this list:
JavaScript:
var $dataActors       = null;
var $dataClasses      = null;
var $dataSkills       = null;
var $dataItems        = null;
var $dataWeapons      = null;
var $dataArmors       = null;
var $dataEnemies      = null;
var $dataTroops       = null;
var $dataStates       = null;
var $dataAnimations   = null;
var $dataTilesets     = null;
var $dataCommonEvents = null;
var $dataSystem       = null;
var $dataMapInfos     = null;
var $dataMap          = null;
var $gameTemp         = null;
var $gameSystem       = null;
var $gameScreen       = null;
var $gameTimer        = null;
var $gameMessage      = null;
var $gameSwitches     = null;
var $gameVariables    = null;
var $gameSelfSwitches = null;
var $gameActors       = null;
var $gameParty        = null;
var $gameTroop        = null;
var $gameMap          = null;
var $gamePlayer       = null;
All of these are objects/arrays. The ones starting with data are loaded from the JSONs in [Yourgame]/data/ and are from the database. The ones starting $game generally are the active arrays. Think of the data ones as the foundation and the game ones as the player choice / game choice. If you mess around with them and console.log([Code here]); pressing F8 to bring up the log you can't go too far wrong.

Either way, happy to help.
 

LTN Games

Master Mind
Resource Team
Xy$
0.01
I'm closing thread due to being addressed & solved if for any reason you would like it re-opened please report the post.
 
Status
Not open for further replies.
Top