Envision, Create, Share

Welcome to HBGames, a leading amateur game development forum and Discord server. All are welcome, and amongst our ranks you will find experts in their field from all aspects of video game design and development.

Increasing a variable and multiples

Hey there, need more help again.

Firstly the variable question:

How do I increase a variable everytime the player takes a step? I've looked at Game_Player (Under the 'increase steps' method, but I don't understand how it increases on movement).

The multiple question:

How would I check if something is a multiple or, say 30? I need something to happen everytime 30 steps has been taken you see.

Thanks for any help.

~Skyline
 
I did that, although I forgot to mention it. Problem is, I don't understand how it adds to it everytime the player takes a step. There's nothing in there that indicates that it should only increase on movement, atleast not to me.

The only thing I can think is the .min at the end of the array, but I doubt that's it.

~Skyline
 
You don't need to check it as there is already a variable that is checking the player's amount of steps and that is $game_party.steps. What do you exactly want to do after 30 steps? Maybe I can throw something up.
 
1) Look in the Game_Character (3) class in each of the movement methods
(move_down, move_left, etc), next look at Game_Character (2) method increase_steps, then note that Game_Player inherits from Game_Character so method increase_steps is overridden for Game_Player's increase steps method.

2) In addition, the % (modulus) operater returns the remainder of the two numbers (5%2 will return 1, 60%6 will return 0, 40%9 will return 4) so if it returned 0 then the first number is divisible by the second number
 
Sion said:
Divide the variable by 30, if its a whole number then the variable was a multiple.

No, it wouldn't work unless the variable or the divisor is a Float, If the two numbers are both Integers then it will return a Integer for example

50 / 30 => 1, 40 / 6 => 6, 36 / 9 => 4

If one (or both) were Float then you would get something like this

50 / 30.0 => 1.6666666, 50.0 / 6.0 => 8.3333333, 36 / 9.0 => 4.0

Its really a messier approach, because then you will have to check if the decimal part of the number is 0.0
 
I made something like this:
Code:
@counter = 0
@steps = 30
if $game_party.steps - @counter > @steps
@steps = @steps + ($game_party.steps - @counter)
end

if $game_party.steps - @counter == @steps
#do something
end

It's a bit complicated, but it works. ^_^
 

Thank you for viewing

HBGames is a leading amateur video game development forum and Discord server open to all ability levels. Feel free to have a nosey around!

Discord

Join our growing and active Discord server to discuss all aspects of game making in a relaxed environment. Join Us

Content

  • Our Games
  • Games in Development
  • Emoji by Twemoji.
    Top