BASIC SCRIPTING QUESTION(RM VX ACE)
Posts
Pages:
1
I believe it's a basic scripting question nevertheless.
This is the problem: I want a variable take a random number between 1 and Variable. The problem is, that the RPGMaker doesn't allow any random numbers between a number and another variable, or two variable. It only takes whole integers.
"Okay, no problem, I'll just see how it's done by scripting."
I tried to, really.
I kinda couldn't find a single decent tutorial about scripting variables. I found one, which made me a very sad boy: http://www.rpgmakervxace.net/topic/2910-scriptingwfz-variables/
Kinda thought about a workaround, involving RM preset settings only, but I'm more interested in a scripting solution: since I'll prolly be having more of those problems with the stuff I'm working on.
I think just a scripting solution to this problem would be enough, should be enough data for me, to figure out how to manually set variables through scripting. So if anyone could help me out here... Would be awesome!
This is the problem: I want a variable take a random number between 1 and Variable. The problem is, that the RPGMaker doesn't allow any random numbers between a number and another variable, or two variable. It only takes whole integers.
"Okay, no problem, I'll just see how it's done by scripting."
I tried to, really.
I kinda couldn't find a single decent tutorial about scripting variables. I found one, which made me a very sad boy: http://www.rpgmakervxace.net/topic/2910-scriptingwfz-variables/
Kinda thought about a workaround, involving RM preset settings only, but I'm more interested in a scripting solution: since I'll prolly be having more of those problems with the stuff I'm working on.
I think just a scripting solution to this problem would be enough, should be enough data for me, to figure out how to manually set variables through scripting. So if anyone could help me out here... Would be awesome!
Do an event->script call like so:
# is the ID of the variable to dump the random number into. ## is the ID of the variable that defines the upper range. n is your lower case, in this case 1. To make it easier you could make a new function in a script like so:
Then call it via event->script calls:
Untested and from memory, let me know if it has an error and what the error is.
$game_variables[#] = Random.rand($game_variables[##] - n) + n
# is the ID of the variable to dump the random number into. ## is the ID of the variable that defines the upper range. n is your lower case, in this case 1. To make it easier you could make a new function in a script like so:
def RandomIntoVariable(lo, hi, targetID) $game_variables[targetID] = Random.rand(hi - lo) + lo end
Then call it via event->script calls:
RandomIntoVariable(1, $game_variables[##], #)
Untested and from memory, let me know if it has an error and what the error is.
The first one goes without any errors, but I only get outputs below 1(0.454539487, etc). For a minute I thought multiplying the number with 10 would solve it, but the numbers are completely random(getting inputs of 4 while 2 should be the max etc).
I don't fully understand why, since the algorithm behind it, is a standard algorithm(my basic knowledge of programming knows at least that much). But for some reason it looks like it's picking a number of max 1 for the ## variable. :S
But it seems memory serves you well, as for the second one is working exactly as I want!
Thanks a lot!
I think I can manage from here on to figure out some more of the variable issues I have :)
I don't fully understand why, since the algorithm behind it, is a standard algorithm(my basic knowledge of programming knows at least that much). But for some reason it looks like it's picking a number of max 1 for the ## variable. :S
But it seems memory serves you well, as for the second one is working exactly as I want!
Thanks a lot!
I think I can manage from here on to figure out some more of the variable issues I have :)
Pages:
1














