{Solved} How to make "Attack" give out a random amount of resource (Rage) every turn

Status
Not open for further replies.

Zuque

Villager
Member
Joined
Dec 27, 2018
Messages
13
Reaction score
0
First Language
Bulgarian
Primarily Uses
RMMV
Hello Everyone and first of all thank you for reading this.
I have a Warrior class in my game and when he uses the Attack skill for the turn I want him to receive 1-5 "rage"
and of course, I want this variable to be random every time it is used.

What I have done:
I have a variable called RandomRageGain in my event initializing and the event is set on AutoRun and of course, afterward the Self Switch A trick.
In my "Attack" skill I have the following code:
Code:
  <Custom Execution>
    $gameVariables.setValue(1, $gameVariables.value(1) + $gameVariables.value(3));
  </Custom Execution>
Variable 1 = Rage
Variable 3 = RandomRageGain

The Problem:
So it does work but it randomly sets it ONE time and that's it, it won't run the RandomRageGain again so the variable will be constant

If you have any ideas about what my problem might be, Id be happy for suggestions.
Thank you again!
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,518
Reaction score
12,052
First Language
English
Primarily Uses
RMMV
Events and self switches have nothing to do with battle. Why are you using an event, why do you have it set to autorun, and why are you setting a self switch?
 

Zuque

Villager
Member
Joined
Dec 27, 2018
Messages
13
Reaction score
0
First Language
Bulgarian
Primarily Uses
RMMV
Events and self switches have nothing to do with battle. Why are you using an event, why do you have it set to autorun, and why are you setting a self switch?
Why are you using an event?
Well, I need to set all the variables for the game at the beginning.
Screenshot (2).png

why do you have it set to autorun?
I want to make sure that the event "Warrior Start Call" is run before the player can move anywhere in the game.

why are you setting a self switch?
well after the code has been run I want the player to be able to move and that won't be possible if an event is set to autorun so I switch it with self switch.

do excuse me if I am not able to understand the meaning of your questions I do hope the answers I have provided will be sufficient.
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,518
Reaction score
12,052
First Language
English
Primarily Uses
RMMV
Alright - that's just initializing the variables. And your random number is going to be set once, at the beginning of the game. If you want it to randomize every time you use it, then you have to do that step again. It's not like setting it to a "range" then every time you use it, it goes and generates another random number within that range.

I suspect something like this is what you're after:

$gameVariables.setValue(1, Math.min(100, Math.max(0, $gameVariables.value(1) + Math.ceil(Math.random() * 3))));



This will get a random number between 1 and 3, and add it to variable 1. It will then make sure the variable stays within the 0 to 100 range.

If you do it like this, you don't need the maximum variable you've set in the common event.
 

Zuque

Villager
Member
Joined
Dec 27, 2018
Messages
13
Reaction score
0
First Language
Bulgarian
Primarily Uses
RMMV
Alright - that's just initializing the variables. And your random number is going to be set once, at the beginning of the game. If you want it to randomize every time you use it, then you have to do that step again. It's not like setting it to a "range" then every time you use it, it goes and generates another random number within that range.

I suspect something like this is what you're after:

$gameVariables.setValue(1, Math.min(100, Math.max(0, $gameVariables.value(1) + Math.ceil(Math.random() * 3))));



This will get a random number between 1 and 3, and add it to variable 1. It will then make sure the variable stays within the 0 to 100 range.

If you do it like this, you don't need the maximum variable you've set in the common event.

Thank you it did the trick, never would I believe that the code was so sophisticated, but then again I have no background in javaScript so I thank you a lot!
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
6,057
Reaction score
4,263
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

What can I sing for my sisters birthday...?

>.<'
Well, I'll have you know that I'm still around, looking for opportunity to resurface with some stuffs.
I like to think of Profile Posts as tiny homes, full of all kinds of unsuspecting suckers "future" friends.... Many of which are of course only going to be excited when a strange man in black suddenly shows up to say hi. :LZSexcite:
Stream will be live shortly with some more Haunting Ground! Today, we encounter a new stalker! Feel free to drop by!
Tried the new Samsung Galaxy S20 Plus today. Very nice device overall, but flagship smartphone prices are getting completely out of control.

Forum statistics

Threads
94,502
Messages
921,477
Members
124,361
Latest member
Kealoa
Top