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.

Steps taken

I am working on an autosave script for my game. I have it set up at the moment to save every time you take a step, but this is extremely laggy.

Instead, I want to make it save if $game_party.steps is divisible by 10 (so every 10 steps it saves).

Here's that part of the script:

Code:
  def initialize_autosave
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if (@hp != actor.hp || 
        @hpm != actor.maxhp || @mp != actor.sp || @mpm != actor.maxsp ||
        [COLOR=Red]@steps != $game_party.steps.to_s[/COLOR])
        autosave
        @hp = actor.hp
        @hpm = actor.maxhp
        @mp = actor.sp
        @mpm = actor.maxsp
        [COLOR=Red]@steps = $game_party.steps.to_s[/COLOR]
      end
    end
  end

I wondered if anybody here could help me?
 
Try this.
Code:
  def initialize_autosave
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if (@hp != actor.hp || 
        @hpm != actor.maxhp || @mp != actor.sp || @mpm != actor.maxsp ||
        [COLOR=Red]$game_party.steps % 10 == 0[/COLOR])
        autosave
        @hp = actor.hp
        @hpm = actor.maxhp
        @mp = actor.sp
        @mpm = actor.maxsp
      end
    end
  end
 
This should work better:
Code:
  def initialize_autosave
    return if $game_party.steps == @steps && $game_party.steps % 10 != 0
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if (@hp != actor.hp || 
        @hpm != actor.maxhp || @mp != actor.sp || @mpm != actor.maxsp)
        autosave
        @hp = actor.hp
        @hpm = actor.maxhp
        @mp = actor.sp
        @mpm = actor.maxsp
        @steps = $game_party.steps
      end
    end
  end
 
Building on Slipknot's code...
Code:
  def initialize_autosave
    return if $game_party.steps == @steps || $game_party.steps % 10 != 0
    for i in 0...$game_party.actors.size
      actor = $game_party.actors[i]
      if @stats[i] != [actor.hp, actor.maxhp, actor.sp, actor.maxsp]
        autosave
        @stats[i] = [actor.hp, actor.maxhp, actor.sp, actor.maxsp]
      end
    end
    @steps = $game_party.steps
  end
Since there can be more than one actor in the party you will have to store their stats in an array.
 

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