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.

Four doubts: refresh in all scenes, delay, random enemy stats and trunc

Hello.
1 and 2- I am trying to make a script that stores the time of the pc itself in variables, both event and script ones. But I can't make it refresh as much as I want... if I start the cript with "begin" it refreshes at the start of every scene and only at the start of every scene, meaning I need to change to other scene to update it. If i start the script with "class Hora_PC" I can do it as I want, but for it I need to add the command "Hora_PC.update" inside the update method of every Scene class...
I also tried to make the method initialize of the script loop "update", but the game crashed for using too much memory (no message, just black screen, and couldn't close it until the windows said it wasn't answering).
1-Is there a way to make the script update in every scene without needing to add "Hora_PC.update" in the refresh of every scene script?
2-Is there a "delay" command in RGSS (for making the script stop for one or two frames and them let it keep going)? I may use it in the loop, but even if I get a good answer for question 1 it may still be useful.

3 and 4- I am also trying to make the enemies more random (meaning the same kind of enemy with different status when battling)... I tried adding to the lines of said stats in Game_Enemies "*(rand(500000)+750000)/1000000" (for a randomness of 25% both up and down),
but I soon noticed it changes the stats EVERY time, not only at the start of battle... I then thought about changing in the Battler scripts, but then would also affect the heroes...
3- Where do I change so I can get the effects I want?
4- Is there a command so I can trunc a value (turn a decimal value back to integer), so I can just use, for example, "maxhp=trunc($data_enemies[@enemy_id].maxhp*(rand(5.0)+7.5)/10.0)". I guess it may be better for the pc instead of the other one (I used so many zeros because of the possible number of... well, numbers... possible in the monster's stats like hp, since I wouldn't use decimals it needed to be a number that multiplied bu any hp number and then divided by a 10*(number of zeros +1) would make as many hp changes as possible)...

I already thank you for your future help, and sorry for any mistakes, I may be good at English, but no one is perfect in another language.
 
1. If you need t only once per scene, you could put the code (or Hora_PC.refresh) before $scene.main in the Main script section. If you need updating every single frame, you could consider putting the code in the update method of Scene_Map and Scene_Battle, as they contain most of the other stuff anyway and are called each frame. Another option is making your own base class for scene (Scene_Base) for example, putting the code in the update method, and making every scene call super, but that might be an overkill.

2. I think sleep(seconds) should do the trick, although you shouldn't rely on it. It'd stop everything I think, so you could also use an loop with Graphics.update in it, but that too isn't the best way. A better option is simply returning from an update method for a while, for example check the Interpreter classes to see how they handle the 'Wait' command. They simply stop updating the interpreter while there's still time to wait.

3. You can have a boolean variable called first and do something like:
Code:
if !@first
# add the random value
@first = true
end
which ensures the code runs only one. Or you could do the stat update somewhere else such as the Scene_Battle class.

4. Try Integer(value) or value.to_i
 
1-I need it to update every frame, but I was hoping not to need to change every scene script's... oh, right, update instead of refresh, sorry, I wasn't with the RMXP open while I wrote it... I am going to post the ready script here to ask everyone if it is fine, if I'm not using things I wouldn't need, this kind of thing, and them I would post both here and in a brazilian site (in portuguese) as a ready script to be used by however wishes to... But having to change every scene script it may be used may be a little confusing... And, unfortunatelly, both your ideas would require this...
I also wrote I added the loop to main, but I actually did so to initialize. I'll change the main post as soon as I post this one...
I forgot to mention, I once tried adding after the end of the class:
Code:
class ($scene-'.new')
  def update
    Hora_PC.update
  end
end
As you may guess, the game didn't even start...
Thanks for your help anyway... Maybe someone else know another way (if there is) now that so many mistakes are going to be fixed...

2- As I said, it may be useful in the future, but for now I would only be able to try it in this script... I made a loop in initalize with update inside it, and put the sleep(1) and Graphics.update inside the loop and inside the method (of course, one at a time and at one place at a time). sleep made no difference when I added it to it, even if it would if I used it in another method... I'll save it for latter, at a time I may be able to find out. Graphics.update made it all be black, but no windows message, looks like it just didn't let the Scenes keep going... And the one of stopping the update... I just can't do it, because I would use it on the update...

3- Why didn't I think of booleans? I feel really stupid right now... Thanks!
That fix my problem. About changing in Scene_Battle, I looked in all Game classes I could think of, but didn't even thought about Scenes... But I think the boolean must be enough.

4- I checked, and integer(value) didn't work, but value.to_i did! Thanks!

Ok, all I need yet are answers to questions 1 and 2. Thanks, Cowlol!
 
...I just thought (a little late, I guess XP) that it would be MUCH easier to get help - and for you to help me - if I posted my script so far...

Code:
class Hour_PC #also tried only using "begin"

  def initialize
    update
  end
  
  def refresh
    $pcsecs = Time.new.sec
    $pcmin = Time.new.min
    $pchour = Time.new.hour
    $pcyear = Time.new.year
    $pccentyear = Time.new.year % 100
    $pcmonth = Time.new.month
    $pcweek = Time.new.wday
    $pcday = Time.new.day
    if $gamebegun
      $game_variables[1] = $pcsecs
      $game_variables[2] = $pcmin
      $game_variables[3] = $pchour
      $game_variables[4] = $pcweek
      $game_variables[5] = $pcday
      $game_variables[6] = $pcmonth
      $game_variables[7] = $pccentyear
    end
  end
  
  def update
    if $pcsec != Time.new.sec or $pcmin != Time.new.min or $pchour != Time.new.hour or $pcyear != Time.new.year % 100 or $pcmonth != Time.new.month or $pcday != Time.new.day
      refresh
    end
  end

end
$gamebegun is a boolean variable that I made become true in Scene_Title just after the line that says "$game_variables = Game_Variables.new". All others must probably be better if I used temp. variables, but I still don't know how to use them...
 

OS

Sponsor

Hey, it may be a little easier to change all of those global variables ($pc) to instance variables (@pc), and to call refresh in the initialize method instead of update. It would also be beneficial to replace $gamebegun with $game_time or something similar. Like this:

Code:
class Hour_PC #also tried only using "begin"

  def initialize
    update
  end
  
  def refresh
    @pcsecs = Time.new.sec
    @pcmin = Time.new.min
    @pchour = Time.new.hour
    @pcyear = Time.new.year
    @pccentyear = Time.new.year % 100
    @pcmonth = Time.new.month
    @pcweek = Time.new.wday
    @pcday = Time.new.day
    $game_variables[1] = @pcsecs
    $game_variables[2] = @pcmin
    $game_variables[3] = @pchour
    $game_variables[4] = @pcweek
    $game_variables[5] = @pcday
    $game_variables[6] = @pcmonth
    $game_variables[7] = @pccentyear
  end
  
  def update
    if @pcsec != Time.new.sec or @pcmin != Time.new.min or @pchour != Time.new.hour or @pcyear != Time.new.year % 100 or @pcmonth != Time.new.month or @pcday != Time.new.day
      refresh
    end
  end

end

class Scene_Title
  alias os_cng command_new_game
  def command_new_game
    $game_time = Hour_PC.new
    os_cng
  end
end

If you use this, place $game_time.update just under $game_screen.update in Scene_Map's update method. You can then create methods or attr_accessor's to access the values in this script, or just use your variables.

I hope this is helpful. Peace!
 

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