[SCRIPTING] [RMMV] CONDITIONAL BRANCH SCRIPT
Posts
Pages:
1
What is wrong with this script? I used Archeia's script call equivalent table as a template, but wasn't sure on the proper syntax:
if ($gameVariables.value($gameVariables.value(1077) = 0)
{gameTemp.reserveCommonEvent(31)}
else
{$gameVariables.setValue(1077, + 1)};
Attempting to check a batch of variables (in sequence) to see if they = 0. I know
how to check all of them at once, but I'm trying to do it individually.
1077 = Variable ID
31 = ID of Common event in database I want to trigger if it passes.
If it fails, I want to adjust 1077 to go up by 1, so it can check the next variable up in the database.
Normally I would use a "Go to Label" command in the else argument, so I can execute the same branch over and over (to check a different variable each time).
I didn't see a script equivalent for "Label" and "Go to Label". How do you do it?
The errors I have been given:
Unexpected Token on both the period in the common event call, and on the curly brace too. It also doesn't seem to care if I include (or omit) the semicolon either.
if ($gameVariables.value($gameVariables.value(1077) = 0)
{gameTemp.reserveCommonEvent(31)}
else
{$gameVariables.setValue(1077, + 1)};
Attempting to check a batch of variables (in sequence) to see if they = 0. I know
how to check all of them at once, but I'm trying to do it individually.
1077 = Variable ID
31 = ID of Common event in database I want to trigger if it passes.
If it fails, I want to adjust 1077 to go up by 1, so it can check the next variable up in the database.
Normally I would use a "Go to Label" command in the else argument, so I can execute the same branch over and over (to check a different variable each time).
I didn't see a script equivalent for "Label" and "Go to Label". How do you do it?
The errors I have been given:
Unexpected Token on both the period in the common event call, and on the curly brace too. It also doesn't seem to care if I include (or omit) the semicolon either.
Okay, so let's write this in a slightly more readable format:
There are a few things wrong with this.
First is your initial if: It opens three sets of brackets, but only closes two. You're also using an assignment operator (=) for comparison. You want to use the strict comparison operator (===) instead. So the line becomes:
Secondly, you're missing the dollar sign on $gameTemp, and all statements should end with a semicolon, not the block.
Thirdly, +1 isn't a valid value to use for the value.
Here's what it should look like:
if ($gameVariables.value($gameVariables.value(1077) = 0) { gameTemp.reserveCommonEvent(31) } else { $gameVariables.setValue(1077, +1) };
There are a few things wrong with this.
First is your initial if: It opens three sets of brackets, but only closes two. You're also using an assignment operator (=) for comparison. You want to use the strict comparison operator (===) instead. So the line becomes:
if ($gameVariables.value($gameVariables.value(1077)) === 0)
Secondly, you're missing the dollar sign on $gameTemp, and all statements should end with a semicolon, not the block.
Thirdly, +1 isn't a valid value to use for the value.
Here's what it should look like:
if ($gameVariables.value($gameVariables.value(1077)) === 0) { $gameTemp.reserveCommonEvent(31); } else { $gameVariables.setValue($gameVariables.value(1077) + 1); }
Regarding your query about the "label" and "go to label", in Javascript proper you'd use either a for loop or a do while loop depending on whether you have a finite number of iterations or need to continue processing until a condition is met.
Thanks yet again! You should be paid to teach this sort of thing.
EDIT: I keep getting the reference error:
Invalid left-hand side in assignment
All the stuff is closed in. Also tried the loops:
while (;;)
ok how does this work? Is it..
while (;;) {code to be repeated, with a break; statement inside to stop it} ?
EDIT: I keep getting the reference error:
Invalid left-hand side in assignment
All the stuff is closed in. Also tried the loops:
while (;;)
ok how does this work? Is it..
while (;;) {code to be repeated, with a break; statement inside to stop it} ?
While doesn't use multiple parameters. Use while(true) instead.
example of a while loop
The output you'll get in the console will be
The while loop loops while the condition is TRUE (i is less than 5) and stops once the condition is FALSE (i is greater than or equal to 5)
Also, I think your error may be caused by the $gameVariables.setValue. The parameters it needs are
so it should be
where 1077 is the variable, and $gameVariables.value(1077) + 1 is the value
var i = 0;
while (i < 5) {
console.log(i);
i += 1;
}
The output you'll get in the console will be
0
1
2
3
4
The while loop loops while the condition is TRUE (i is less than 5) and stops once the condition is FALSE (i is greater than or equal to 5)
Also, I think your error may be caused by the $gameVariables.setValue. The parameters it needs are
$gameVariables.setValue(variableId, value)
so it should be
$gameVariables.setValue(1077, $gameVariables.value(1077) + 1);
where 1077 is the variable, and $gameVariables.value(1077) + 1 is the value
Oh sugar, I forgot the variable ID argument in the code I posted, well spotted.
Very good explanation on how to understand
1)how a loop functions and
2)how to implement it!
I'm not going to stop trying this until it works properly. I learned:
A decent editor really helps! Color coding on sublime text makes it all more legible and catches some mistakes too. Just wish copied and pasted stuff into the game editor didn't get chopped off! It may instill lazy habits...
How did you think I came up with the first train wreck I posted?
1)how a loop functions and
2)how to implement it!
I'm not going to stop trying this until it works properly. I learned:
A decent editor really helps! Color coding on sublime text makes it all more legible and catches some mistakes too. Just wish copied and pasted stuff into the game editor didn't get chopped off! It may instill lazy habits...
How did you think I came up with the first train wreck I posted?
I wouldn't say it was a train wreck, it was a solid enough guess at what you needed to do and provided a springboard for more experienced members to help you refine it. That's what a help topic should be. :)
Pages:
1














