Trigger Switches in Script

● ARCHIVED · READ-ONLY
Started by Halfmoon Media 10 posts View original ↗
  1. Not 100% sure if this is the right topic, or if it should be posted under script support... I've seen similar posts in this topic before, but if I'm in the wrong place, let me know, move the thread, whatever works best is okay with me.

    What I'm trying to do: Create a script command to restore certain switches & variables to a specific value.

    Script I am trying this in: Yanfly's System Options.

    I've noticed that Yanfly more or less doesn't really respond to support questions on their site, at least they haven't for a while, which is why I'm posting here.

    I've decided to replace the options "Return to Title Screen" and "Exit Game" with a "Restore Default Settings" and "Save and Go Back".  "Save..." works fine with just a :return_scene command, but "Restore..." is a bit harder.

    Right now, I have this in the SYSTEM module:

    Spoiler
       SWITCHES = {      14 => false,

          15 => true,

          13 => true,

          1 => false

        }

        

        VARIABLES = {

          13 => 2,

          14 => 1

        }
     

    Near the bottom of the script, I have this:


     def create_command_window

        @command_window = Window_SystemOptions.new(@help_window)

        @command_window.set_handler:)cancel, method:)return_scene))

        @command_window.set_handler:)set_restore, method:)command_set_restore))

        @command_window.set_handler:)go_back, method:)return_scene))

      end

      

      #--------------------------------------------------------------------------

      # command_to_title

      #--------------------------------------------------------------------------

      def command_set_restore

        YEA::SYSTEM::SWITCHES.each do |id, bool|

          $game_switches[id] = bool

        end

        YEA::SYSTEM::VARIABLES.each do |id, val|

          $game_variables[id] = val

        end

      end

     

    Like I said, :go_back is working just fine, but when I try to select :set_restore, the game freezes. It doesn't crash, doesn't give an error, just freezes.  :(

     

    What am I doing wrong? 
  2. try this

    Code:
      def command_set_restore    YEA::SYSTEM::SWITCHES.each_key {|id| $game_switches[id] = SWITCHES[id]}    YEA::SYSTEM::VARIABLES.each_key {|id| $game_variables[id] = VARIABLES[id]}  end
  3. Didn't work.

    But, I got an error this time instead: "Uninitialized constant Scene_System::SWITCHES"
  4. Sorry I assumed you defined the SWITCHES in the yea module. Where did you define them?

    nm looked a the code again. change it to this

    Code:
      def command_set_restore    YEA::SYSTEM::SWITCHES.each_key {|id| $game_switches[id] = YEA::SYSTEM::SWITCHES[id]}    YEA::SYSTEM::VARIABLES.each_key {|id| $game_variables[id] = YEA::SYSTEM::VARIABLES[id]}  end
  5. I think that's part of the problem, I thought I DID define them, but it keeps telling me I didn't. And since I thought I did it right, I'm at a loss as to why it's wrong D:
  6. Moving to RGSSx Script Support

    :) try this ...

    Code:
     def command_set_restore    YEA::SYSTEM::SWITCHES.each do |id, bool|      $game_switches[id] = bool    end    YEA::SYSTEM::VARIABLES.each do |id, val|      $game_variables[id] = val    end    return_scene  end
    You haven't told it what to do with the window/scene after executing that command. By default, selecting an option in a Window_Command window deactivates the window, but doesn't activate another or return to the scene. So you've got to tell it whether you want to reactivate the window (via @command_window.activate) or go back to the previous scene.
  7. Shaz said:
    Moving to RGSSx Script Support

    :) try this ...

    def command_set_restore YEA::SYSTEM::SWITCHES.each do |id, bool| $game_switches[id] = bool end YEA::SYSTEM::VARIABLES.each do |id, val| $game_variables[id] = val end return_scene endYou haven't told it what to do with the window/scene after executing that command. By default, selecting an option in a Window_Command window deactivates the window, but doesn't activate another or return to the scene. So you've got to tell it whether you want to reactivate the window (via @command_window.activate) or go back to the previous scene.
    That worked...! I had been so close, too! Thank you!

    Now my only other issue is: How do you connect the BGM/BGS/SFX volume to this? I thought adding

    Spoiler
       @volume = {}    @volume[:bgm] = 100

        @volume[:bgs] = 100

        @volume[:sfx] = 100
    would work, but the volume levels stay at whatever I altered them to before hitting "restore"
  8. What do you mean "while you have the system open"? You either want it as a selectable command or you don't. If you don't, just put the call/code in the appropriate OTHER place.
  9. ^^^^^Read edited post
  10. *bump