I set variable 1 and 2 to random. I am trying to write a script that adds variable 1 and 2 and displays it as one of the choices for the user to pick. I have had no luck getting any output other than zero. Any suggestions?
Using the script command
RPG Maker MV SupportThis has nothing to do with scripts.
Use Control Variables to set a variable to a random number
Then use Control Variables to add to the same variable, again choosing a random number
Then I think you can use \v[x] in a Show Choices command, where x is the variable id
Use Control Variables to set a variable to a random number
Then use Control Variables to add to the same variable, again choosing a random number
Then I think you can use \v[x] in a Show Choices command, where x is the variable id
I didn't think of that thank you. What if I wanted to do something more difficult like add the squares of two random numbers and then take the square root? Or do something with sine or cosine? I have been messing around with the $gameVariables but not having any luck.
If the operation can be simulated by a basic mathematical operation (squares are just multiplications), then you can use control variable with the basic operations.
If the operation requires a more complex mathematical function, then you need to use the mathematical code from javascript - which means you have to learn the basics of programming in javascript first, because program code is not exactly the same as basic mathematical operations.
If the operation requires a more complex mathematical function, then you need to use the mathematical code from javascript - which means you have to learn the basics of programming in javascript first, because program code is not exactly the same as basic mathematical operations.
Thank you. I will try that for the easier operations. I am attempting to use javascript, I am still stuck on using a random variable that I have created in the game. For example I have named variable 1, angle and have set it to randomize between 10 and 40. In the script I am trying to take the sine of the randomized angle but it keeps giving me 0. I have tried the following:
$gameVariables[11] = math.sin($gameVariables[1])
Then to display I have /V[11]
I am assuming I will have to convert the angle to radians but will worry about that later.
Any guidance in my error would be appreciated. Just not seeing it.
$gameVariables[11] = math.sin($gameVariables[1])
Then to display I have /V[11]
I am assuming I will have to convert the angle to radians but will worry about that later.
Any guidance in my error would be appreciated. Just not seeing it.
Make sure you are telling us EXACTLY what you are doing. I see two issues in the above that could be reasons why it's not working, or could just be typos you've made when posting.
It is Math.sin, not math.sin
and to display, it is \V[11], not /V[11].
For these reasons, it's often better to take a screenshot of your event and post it here, than to just type things out, because we could spend a lot of time trying to figure something out only to realize you've typed it out differently and we're not really looking at what you've actually got happening in your game at all.
It is Math.sin, not math.sin
and to display, it is \V[11], not /V[11].
For these reasons, it's often better to take a screenshot of your event and post it here, than to just type things out, because we could spend a lot of time trying to figure something out only to realize you've typed it out differently and we're not really looking at what you've actually got happening in your game at all.
mmm ... it's strange that it's not giving you an error message, because you've got the wrong syntax for the variables.
In MV, the correct script command to get the value of a variable is $gameVariables.value(n) and the command to set a value is $gameVariables.setValue(n, value).
However, you don't need to use a script command - you can use Control Variables and put the formula in the Script box (right at the bottom of the Control Variables dialogue). So:
After the event is done, if it still gives you 0, you can hit F9 to debug and see what is in variable 1 and 2 and do the calculation yourself. That might give you a hint at what's wrong.
In MV, the correct script command to get the value of a variable is $gameVariables.value(n) and the command to set a value is $gameVariables.setValue(n, value).
However, you don't need to use a script command - you can use Control Variables and put the formula in the Script box (right at the bottom of the Control Variables dialogue). So:
Code:
Control Variables: #0001 Angle = Random 10..40Control Variables: #0002 Hyp = Random 2..20Control Variables: #0011 Sin = Script: $gameVariables.value(2) * Math.sin($gameVariables.value(1))Control Variables: #0012 Cos = Script: $gameVariables.value(2) * Math.cos($gameVariables.value(1))Control Variables: #0013 Tan = Script: $gameVariables.value(2) * Math.tan($gameVariables.value(1))...
Thank you works perfectly.
Original thread: https://forums.rpgmakerweb.com/threads/using-the-script-command.50644/
