When to update variables (like steps taken game data)

Discussion in 'RGSSx Script Support' started by Shion Kreth, Sep 13, 2014.

  1. Shion Kreth

    Shion Kreth White Knight Veteran

    Messages:
    281
    Likes Received:
    47
    Location:
    Ottawa, Canada
    First Language:
    English
    I have yanfly's save engine reporting various variables for tracking game stats, like battles fought and steps taken. Since those are kept track of by rpgmaker itself I havn't programmed in anything to update those variables. I'm curious at which points people go about fitting in setting those variables to the game data. I know it could easily be set as a parallel process event always running, but I hate having lag from events so I've considered updating them on transition points or when save access is granted. I'm wondering what clever ways other people have thought of.
     
    #1
  2. Wavelength

    Wavelength Pre-Merge Boot Moderator

    Messages:
    4,381
    Likes Received:
    3,657
    Location:
    Florida, USA
    First Language:
    English
    Primarily Uses:
    RMVXA
    A lot of these things are actually tracked by RPG Maker's default scripts and just aren't shown to the player by default.  For example, the total number of steps the player has taken.  @steps is a variable that belongs to the Game_Party class, just like @gold is.  (Similarly, @battle_count is a variable that belongs to Game_System.)

    When the player takes a step, the "increase_steps" method is called:

    #-------------------------------------------------------------------------- # * Move Straight # d: Direction (2,4,6,8) # turn_ok : Allows change of direction on the spot #-------------------------------------------------------------------------- def move_straight(d, turn_ok = true) @move_succeed = passable?(@x, @y, d) if @move_succeed set_direction(d) @x = $game_map.round_x_with_direction(@x, d) @y = $game_map.round_y_with_direction(@y, d) @real_x = $game_map.x_with_direction(@x, reverse_dir(d)) @real_y = $game_map.y_with_direction(@y, reverse_dir(d)) increase_steps elsif turn_ok set_direction(d) check_event_trigger_touch_front end endThe increase_steps method adds one to this variable:

    #-------------------------------------------------------------------------- # * Increase Steps #-------------------------------------------------------------------------- def increase_steps @steps += 1 endThis has a very slight effect on game speed and slowdown, because yes, it will run every single time the player takes a step.  But because it doesn't need to go through all of the "should I run an event" logic, I believe it will have a much lesser effect on game speed and slowdown than it would if something similar were running as a parallel process.

    So Yanfly's save script is probably just creating a way to write this variable to the save screen, and if there are other variables that aren't tracked by RPG Maker by default, he probably inserted counting logic into similar, appropriate places.  If you wanted to track how many tiems the player visited the main menu screen, for example, you could define it as a property of Game_Party (or Game_System or any other class that has only one instance), and increment that variable by 1 in the start method for Scene_Menu.
     
    #2
  3. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,421
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    I have a Linked Variables script that you could use, that will update the value in variables at the moment the variable is accessed.
     
    #3
  4. Shion Kreth

    Shion Kreth White Knight Veteran

    Messages:
    281
    Likes Received:
    47
    Location:
    Ottawa, Canada
    First Language:
    English
    The linked variables script had an unfortunate habit of updating the variables with non-present data while choosing a save file when launching the game. :)

    A little mini script to update variables(specifically 1 to steps taken and 2 to battles fought, but anyone else using yanfly's save engine might want the full range of game data options) when the menu is called might be an efficient solution. I'd be very appreciative If a generous and knowledgeable soul could help walk me through scripting that(or tell me why that idea won't work at all), my scripting skills are... well, I don't PANIC when looking at a page of code anymore; that's progress. ;)
     
    #4
  5. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,421
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    I've moved this thread to RGSS3 Script Requests. Please be sure to post your threads in the correct forum next time. Thank you.


    Can you give a link to Yanfly's script, and a list of EXACTLY what information you want shown on the save screen?


    None of the suggestions we've given you will suit your purposes, because they are all based on the CURRENT game, not loading data from a saved game.


    What do you want to show, where do you want to show it (a mock-up of the screen would be great, showing the format and the new values you want included).
     
    Last edited by a moderator: Sep 16, 2014
    #5
  6. Shion Kreth

    Shion Kreth White Knight Veteran

    Messages:
    281
    Likes Received:
    47
    Location:
    Ottawa, Canada
    First Language:
    English
    Here's a screenshot: http://rpgmaker.net/media/content/users/32143/locker/savescreen.jpg

    I really think it would be easier to just update those variables at specific points in-game(during a current game), steps and battle count, just like the other variables get updated, just because battles and steps are updated that much more I wanted to find a way to update them discretely regularily(like when calling the menu), and I think scripting in a way to do that would be easier than modifying yanfly's script, but it's up for consideration; the screenshot should say it all.

    Here's the save engine: https://github.com/Archeia/YEARepo/blob/master/Menu/Ace_Save_Engine.rb
     
    #6
  7. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,421
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    I REALLY think you need to try and comprehend the difference between VARIABLES being updated as you play a game (ie - variables that belong to the CURRENT game), and what is in a save file.


    Steps taken, battles fought, that apply to the SAVE FILE are kept in the save file. They will only change when you load the save file and continue playing.


    Steps and battle count ARE updated as you play. Why would you want values on your save file screen to change when you have not done a save? Or values in OTHER save files based on the current game?


    Is your screenshot PURELY from the script, or have you made modifications? If so, what have you modified? If that is purely from the script, as it is, then I say the script is doing exactly what it's meant to be doing, and maybe you misunderstand what it's all about. It is showing the battle count and steps in THAT SAVE FILE - not the game you are playing now.
     
    #7
  8. Shion Kreth

    Shion Kreth White Knight Veteran

    Messages:
    281
    Likes Received:
    47
    Location:
    Ottawa, Canada
    First Language:
    English
    Shaz, I don't think I've effectively communicated what I want to accomplish here. I just want an efficient way to passively set variables 1 and 2 to game data steps and battle count in the current game I'm playing, exclusively for the current game I'm playing, without having to run a parallel process or anything else intensive that may cause lag, which the save engine script simply reports the values of those variables, at the time of saving, in the save menu. I don't appreciate all the suggesting what I do and don't understand and what I should 'REALLY' try to comprehend; that comes off as very condescending to me. And yes, the screenshot is 'PURELY' from the script.
     
    #8
  9. Sarlecc

    Sarlecc Veteran Veteran

    Messages:
    454
    Likes Received:
    209
    First Language:
    English
    Primarily Uses:
    RMMV
    You could do it like this for steps:

    class Game_Party < Game_Unitdef increase_steps@steps += 1$game_variables[1] = @steps #1 is any game_variable you wantendend
    Then just add the variable to the column_variables array that is in YEAs save engine. This would allow it to be updated whenever the person walks without the need for an event. For battle count it is basically the same:

    module BattleManagerdef self.battle_start $game_system.battle_count += 1 $game_variables[2] = $game_system.battle_count # line that gets added $game_party.on_battle_start $game_troop.on_battle_start $game_troop.enemy_names.each do |name| $game_message.add(sprintf(Vocab::Emerge, name))end if @preemptive $game_message.add(sprintf(Vocab::preemptive, $game_party.name)) elsif @surprise $game_message.add(sprintf(Vocab::Surprise, $game_party.name)) end wait_for_messageendend
    Hope this helps.
     
    #9
    Shion Kreth likes this.
  10. Shion Kreth

    Shion Kreth White Knight Veteran

    Messages:
    281
    Likes Received:
    47
    Location:
    Ottawa, Canada
    First Language:
    English
    Then just add the variable to the column_variables array that is in YEAs save engine. This would allow it to be updated whenever the person walks without the need for an event. For battle count it is basically the same:

    module BattleManagerdef self.battle_start $game_system.battle_count += 1 $game_variables[2] = $game_system.battle_count # line that gets added $game_party.on_battle_start $game_troop.on_battle_start $game_troop.enemy_names.each do |name| $game_message.add(sprintf(Vocab::Emerge, name))end if @preemptive $game_message.add(sprintf(Vocab::preemptive, $game_party.name)) elsif @surprise $game_message.add(sprintf(Vocab::Surprise, $game_party.name)) end wait_for_messageendend
    Hope this helps.

    Thanks Sarlecc, that works perfectly, AND I understood what you were saying. Wavelength too, I know you said pretty much the same thing for steps, and you were correct it's produced no lag. So for that little steps check in class Game_party.. I just stuck that under materials and it's working; that's what I was supposed to do? (the battle one I did put in yanfly's battle engine script after I was looking in there wondering why those 'enemy appeared' messages seemed so unfamiliar :p )
     
    #10
  11. Sarlecc

    Sarlecc Veteran Veteran

    Messages:
    454
    Likes Received:
    209
    First Language:
    English
    Primarily Uses:
    RMMV
    Yea the step one should work under materials. Reason you were getting those enemy appeared messages was because I had the line in the default battleManager module. So basically I think you could have placed that line in either the battleManger Module or in yanfly's battle engine.
     
    #11
  12. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,421
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    That is EXACTLY what my script does, but when you used it, you complained because it was always showing the current amount - if you started a new game and had taken 0 steps, it showed 0. If you loaded a game that said 50 steps and you took 10 more, it would show 60. For some reason you didn't like that. And you started talking about save files and I assumed you wanted to show the number of steps (or battles) from that save file, on that save file slot, which is NOT the current game, and has nothing to do with what's on the save file screen.


    Perhaps you should explain what you want and NOT talk about save files, because keeping track of something in game has nothing to do with what displays on the save file screen.


    The suggestions you have been given above are EXACTLY what that script does. I don't know why you say they work and the script didn't.
     
    Last edited by a moderator: Sep 17, 2014
    #12
  13. Shion Kreth

    Shion Kreth White Knight Veteran

    Messages:
    281
    Likes Received:
    47
    Location:
    Ottawa, Canada
    First Language:
    English
    Because your script was NOT working with the save engine, as when I began a game and opened the save menu it set ALL the variables for ALL the saves to zero, and when a save file was loaded and I opened the save menu it would set ALL the other save files to the CURRENT game's variables, which you've ALREADY proclaimed is the fault of Yanfly's script being 'wrong' and accessing the wrong data. It has NOTHING to do with my explanation, I do not understand WHY you are being so aggressive about this.
     
    #13
  14. Sarlecc

    Sarlecc Veteran Veteran

    Messages:
    454
    Likes Received:
    209
    First Language:
    English
    Primarily Uses:
    RMMV
    Note something I did forget about yesterday was aliasing the methods for greater compatibility if placed under materials.

    If I am correct on how to do this:

    module BattleManagerclass <<self; alias sar_battle_start_ace battle_start; enddef self.battle_startsar_battle_start_ace$game_variables[2] = $game_system.battle_count # line that gets addedendendclass Game_Party < Game_Unitalias sar_increase_steps_ace increase_steps #what this does is from my understanding of it is adds new information to the old method without completely redefining it.def increase_stepssar_increase_steps_ace #alias being accessed$game_variables[1] = @steps #1 is any game_variable you wantendend
    Sorry about not mentioning this yesterday had a pretty bad headache. Anyway if I set this up correctly should work 100% under materials.
     
    #14
  15. Shion Kreth

    Shion Kreth White Knight Veteran

    Messages:
    281
    Likes Received:
    47
    Location:
    Ottawa, Canada
    First Language:
    English
    Sorry about not mentioning this yesterday had a pretty bad headache. Anyway if I set this up correctly should work 100% under materials.
    Alright, that one I understand a little less. What's the difference?
     
    #15
  16. Sarlecc

    Sarlecc Veteran Veteran

    Messages:
    454
    Likes Received:
    209
    First Language:
    English
    Primarily Uses:
    RMMV
    Basically instead of redefining everything in the method's it just adds the following line: $game_variables[2] = $game_system.battle_count to the battle_start method in the BattleManager module. And the line $game_variables[1] = @steps to the increase_steps method in the class Game_Party which is a sub class to Game_Unit.

    Aliasing methods provides a lot more compatibility to scripts lets say for instance yanfly's battle engine didn't alias any methods. Well if you imported another script that uses those methods you could get errors, weird bugs or have it work correctly (depending on where you placed the new script).

    Hopefully I make sense. ;)
     
    #16
  17. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,421
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    :) I am not being aggressive. I'm just highlighting the words that you seemed to have been missing in all of our PM conversations. Now that you've provided a more clear explanation, I understand what the problem was.
     
    #17
  18. Shion Kreth

    Shion Kreth White Knight Veteran

    Messages:
    281
    Likes Received:
    47
    Location:
    Ottawa, Canada
    First Language:
    English
    ... I trust that you know what you're doing and that it's better. ;) Alright alright, I think I get that it's not changing things other scripts may use which could cause issues this way. But it doesn't mean I know, in scripting terms, what defining, method, module, sub class or aliasing means. ;)

     

    Well I know I'm not going to win an argument with you, but I still say you were completely talking down to me.. and it really rubs me the wrong way.
     
    Last edited by a moderator: Sep 18, 2014
    #18
  19. Shaz

    Shaz Veteran Veteran

    Messages:
    37,712
    Likes Received:
    11,421
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    Capitals are used for emphasis too you know - they're not always yelling, especially when it's just a word here or there. I can't help if you misinterpret things.
     
    #19
  20. Shion Kreth

    Shion Kreth White Knight Veteran

    Messages:
    281
    Likes Received:
    47
    Location:
    Ottawa, Canada
    First Language:
    English
    Now you're just being inflammatory.
     
    #20

Share This Page