The RPG Maker Resource Kit

RMRK RPG Maker Creation => RPG Maker General => General Scripting => Topic started by: Fizzly on May 24, 2014, 10:50:17 PM

Title: Reseting step counter and time (not the timer)
Post by: Fizzly on May 24, 2014, 10:50:17 PM
Hello,
I need to reset (set to 0) step counter and timer (both are build-in RM features) in RMVX Ace.
Want to do that via call script command, but how to...?
Title: Re: Reseting step counter and time (not the timer)
Post by: modern algebra on May 24, 2014, 11:48:15 PM
To do the step counter, you could insert the following into its own slot in the Script Editor:

Code: [Select]
class Game_Party
  attr_writer :steps
end

Then, in a script command of an event, simply put:
Code: [Select]
$game_party.steps = 0

I'm not sure what you mean by the timer. If you are talking about the in-game timer, then it is controlled by the Control Timer event command. Just select start and the time to which you want to reset it.
Title: Re: Reseting step counter and time (not the timer)
Post by: Fizzly on May 24, 2014, 11:55:53 PM
By the time (not timer) I mean this one:
http://ifotos.pl/zobacz/thisPNG_eepepxs.PNG/
Need to reset this without exiting game to t he title.
Step command are just above. Tried to use your help, but didn't make it... I don't understand how to use this:
Code: [Select]
class Game_Party
  attr_writer :steps
end
Title: Re: Reseting step counter and time (not the timer)
Post by: modern algebra on May 25, 2014, 12:10:14 AM
Open the Script Editor (F11). Below Materials but above Main, insert a new slot. Paste that code into the blank page on the right-hand side. Give the slot a name so that you know it's there.

Playtime is a little more complicated, but do the same thing and create a new slot in the left-hand list around the same place. Then paste the following code into the blank page on the right-hand side:

Code: [Select]
class Game_System
  def reset_playtime
    @rp_frames_at_last_reset = Graphics.frame_count
  end
  def playtime
    @rp_frames_at_last_reset = 0 unless @rp_frames_at_last_reset
    (Graphics.frame_count - @rp_frames_at_last_reset) / Graphics.frame_rate
  end
end

In a script command in an event, use the following code:

Code: [Select]
$game_system.reset_playtime
Title: Re: Reseting step counter and time (not the timer)
Post by: Fizzly on May 25, 2014, 12:25:36 AM
Thanks for the help, modern, but it does not work. No error or something, but both steps and playtime are still not 0. Tried with both.
Title: Re: Reseting step counter and time (not the timer)
Post by: modern algebra on May 25, 2014, 12:35:22 AM
Ah, well go to Game_Interpreter and find line 617:

Code: [Select]
      when 4  # play time
        return Graphics.frame_count / Graphics.frame_rate

Change it to:

Code: [Select]
      when 4  # play time
        return $game_system.playtime

Why do you want to reset playtime anyway?

Also, you could have done that much through events anyway. You only need scripts to change them in the save menu.

The steps one works.
Title: Re: Reseting step counter and time (not the timer)
Post by: Fizzly on May 25, 2014, 11:52:26 AM
I can do this through events? How?

Code: [Select]
      when 4  # play time
        return $game_system.playtime
Also don't work for me. Dont know why, but still can't set play time to 0  ;9
Why do I need to reset time and steps? Making Sokoban-like game, and need to reset moves while reseting level.

Edit: Found answer for the steps: http://forums.rpgmakerweb.com/index.php?/topic/21155-step-counter-deleting-steps/
And I think I'll do the time (seconds) via variable with incrementation. Thank you anyway modern for your help!
Title: Re: Reseting step counter and time (not the timer)
Post by: modern algebra on May 25, 2014, 12:49:24 PM
Both of those work for me, so it might be that you have another script interfering.

Anyway, to do it with events, you'd use two in-game variables; let's call them X and Y.

Whenever you want to reset the playtime, set Variable X to Play Time through the Control Variables command:

@>Control Variables: [0001: X] = Play Time

Then, whenever you want to retrieve the current playtime, set Y to play time, then subtract X, like this:

@>Control Variables: [0001: X] = Play Time
@>Control Variables: [0002: Y] -= Variable [0001: X]

Variable Y would then hold the play time since the last time it was reset.

Again though, that would not affect playtime as it is shown on the save file.
Title: Re: Reseting step counter and time (not the timer)
Post by: Fizzly on May 25, 2014, 03:13:30 PM
Thanks modern_algebra for your kind help.