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.

New Game Switches.

boon

Sponsor

Hello, I saw a thread on this recently but cannot find it.

Is there a way to keep certain switches on in the game?

Like in the game you get to a point that sets Switch 40 on. As long as one save file has that switch set to true, then all the games will have it set to true.

Is there a way to do this?
 

khmp

Sponsor

Yup you would need to partially load each save file until you encountered a save file with the switch on. Let me put some code together to demonstrate.

[edit: Sorry for the lateness of this]
Code:
SWITCH_TO_CHECK = 40
$switch_on = false

saves = Dir.glob('Save*.rxdata')
# If we have one or more saves.
if saves.size > 0
  saves.each do |save|
    # Open the save file
    file = File.open(save, "rb")

    # Load all the unnecessary stuff to get to the switches.
    characters = Marshal.load(file)
    frame_count = Marshal.load(file)
    game_system = Marshal.load(file)
    game_switches = Marshal.load(file)

    # Decide if we have found our switch active or not.
    if game_switches[SWITCH_TO_CHECK]
      $switch_on = true
      file.close
      break
    end
    file.close
  end
end

For script installation instructions please refer to the FAQ. If any save has the switch specified by the constant, SWITCH_TO_CHECK which as per your suggestion is at 40, the global boolean $switch_on will be active. You will be able to test this boolean from anywhere.

Good luck with it Boonzeet! :thumb:
 

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