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.

Turning on a switch

What statement is used to turn on a specified switch?

I'm thinking it's:

Code:
$game_system.switches = data.switches(x)(

or

Code:
@data.switches(x) = true

but I have absolutely no idea.
I want to be able to incorporate it in this script after the conditional branch that checks if a save file exists:

Code:
class Scene_Title

  alias_method :zeriab_scene_title_main, :main

  def main

    alias :main :zeriab_scene_title_main

    load_database

    # Select the starting map and coordinates

    $data_system.start_map_id = 1

    $data_system.start_x, $data_system.start_y = 8, 5

    command_new_game

  end

  if FileTest.exist?("Save#{i+1}.rxdata")

    $game_system.switches = 

  def load_database

    # Load database

    $data_actors        = load_data("Data/Actors.rxdata")

    $data_classes       = load_data("Data/Classes.rxdata")

    $data_skills        = load_data("Data/Skills.rxdata")

    $data_items         = load_data("Data/Items.rxdata")

    $data_weapons       = load_data("Data/Weapons.rxdata")

    $data_armors        = load_data("Data/Armors.rxdata")

    $data_enemies       = load_data("Data/Enemies.rxdata")

    $data_troops        = load_data("Data/Troops.rxdata")

    $data_states        = load_data("Data/States.rxdata")

    $data_animations    = load_data("Data/Animations.rxdata")

    $data_tilesets      = load_data("Data/Tilesets.rxdata")

    $data_common_events = load_data("Data/CommonEvents.rxdata")

    $data_system        = load_data("Data/System.rxdata")

    # Make system object

    $game_system = Game_System.new

  end

end

Line 12 is where I want it. (Btw, special thanks to Zeriab for the above script! You saved my game!!!)
 
Thanks. Now I have another problem though. When I inserted that statement it came up with an error saying local variable 'i' is undefined or something, so I typed above that

for i in 0..3

but then it came up with a syntax error. Am I even putting any of this in the right place? lol
I'm trying to make it so that the system checks if there's a save file and if so, turns the switch on. I put it in this script because it automatically transfers the player to the map after a couple of splash screens, and they're the first things that come up in the game.
 
First, it seems like you put that code into the wrong place.
Ruby:
  def main

    alias :main :zeriab_scene_title_main

    load_database

    # Select the starting map and coordinates

    $data_system.start_map_id = 1

    $data_system.start_x, $data_system.start_y = 8, 5

    command_new_game

  end

 # the following code is not inside the main method

  if FileTest.exist?("Save#{i+1}.rxdata")

    $game_system.switches =
So, you have to place the "end" after that code.

If you get error messages, you should post them like they are shown. Without a line I can only guess what exactly is the problem.

Code:
class Scene_Title

  alias_method :zeriab_scene_title_main, :main

  def main

    alias :main :zeriab_scene_title_main

    load_database

    # Select the starting map and coordinates

    $data_system.start_map_id = 1

    $data_system.start_x, $data_system.start_y = 8, 5

    command_new_game

    1.upto(4) do |n|

      if FileTest.exist?("Save#{n}.rxdata")

        $game_switches[n] = true

      end

    end

  end

 

  def load_database

    # Load database

    $data_actors        = load_data("Data/Actors.rxdata")

    $data_classes       = load_data("Data/Classes.rxdata")

    $data_skills        = load_data("Data/Skills.rxdata")

    $data_items         = load_data("Data/Items.rxdata")

    $data_weapons       = load_data("Data/Weapons.rxdata")

    $data_armors        = load_data("Data/Armors.rxdata")

    $data_enemies       = load_data("Data/Enemies.rxdata")

    $data_troops        = load_data("Data/Troops.rxdata")

    $data_states        = load_data("Data/States.rxdata")

    $data_animations    = load_data("Data/Animations.rxdata")

    $data_tilesets      = load_data("Data/Tilesets.rxdata")

    $data_common_events = load_data("Data/CommonEvents.rxdata")

    $data_system        = load_data("Data/System.rxdata")

    # Make system object

    $game_system = Game_System.new

  end

end
 
It'd be easier to use...

[rgss]    4.times do |n|
      $game_switches[n+1] = FileTest.exist?("Save#{n+1}.rxdata")
    end
[/rgss]

If it's false, nothing serious will happen but if it's true, the switch will be activated.
 

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