I’m trying to make a battle system.
Your enemies will hit you, and your health will decrease in random.
So I’m using *rand command.
Ex: *rand health 70 100
Code works fine. But there is a problem.
Imagine that you are in the beginning of a battle.
Your health is 100.
The enemy hits you, and your health decreases between 70 and 100.
Lets say “80 Health” lost.
When my health drops to 80, I take a look at the stats screen and see that my health is now 80.
When I say “NEXT” to see the actual battling scene, and then press Stats button again, my health decreases between 70 100 again.
Now, my health is 74 and I chose nothing.
“NOTE: My health is not going under 70”
If I repeat this page switching thing, my health decreases to 88, 91, 72, all random numbers between 70 and 100.
And all I do is just switching the screens.
I think, everytime I open the scene, *rand command starts function again.
How can I solve this?
I want to decrease the health just once.
Please post your code, you’ve probably put the function in the wrong place, but I can’t be sure without seeing it.
Also you don’t want it to set your health to a random number between bla bla - You want it to MINUS a rand value between x and y from your currenthealth and then set that new value as currenthealth, else you actually have a chance of your health going up…
First, this is a reported bug that CoG (currently) does not consider big enough to fix. To put it simply *rand does not like the stats screen, and the stats screen does not like *rand. What causes it, is that any time you pull up the stats screen, upon leaving it every *function fires again. For most functions, this isn’t a problem. No matter how many times you “*set foo + 5”, you’re always going to end up with foo being five more than it was at the start. That is not true with *rand, which is the point. There are two ways to handle this.
Don’t use a stats screen. If you disable it, you don’t have to worry about it. You can always display the stats intermittently. This is easier, but really doesn’t fix the problem.
*rand every variable you would need before you need them. Let me give you an example.
*rand d10_roll_1 1 10
*set health - d10_roll_1
Now, there are two pages there, the one before the *page_break, and the one after it. If you access the stats screen on the first page, it rerolls d10_roll_1, however, as d10_roll_1 doesn’t actually do anything on that page, there is no effect. If you go to the next page, and access the stats screen, when you return, your health will remain at the same level, as the *rand is not recalled, only the *set.
So, the trick is to *rand every die roll you’ll need before the battle begins, then call them up when actually in the fight. You could probably also set it up so that each turn of the battle not only executes the last set of commands, but also rolls up the next set too if you wanted to.