Trigger Switches in Script

Discussion in 'RGSSx Script Support' started by Halfmoon Media, Oct 13, 2014.

  1. Halfmoon Media

    Halfmoon Media Illustrator, Eventer, Writer Veteran

    Messages:
    61
    Likes Received:
    9
    Location:
    A World Without End
    First Language:
    English
    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:

       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? 
     
    #1
  2. Venka

    Venka Veteran Veteran

    Messages:
    945
    Likes Received:
    360
    Location:
    United States
    First Language:
    English
    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
     
    #2
  3. Halfmoon Media

    Halfmoon Media Illustrator, Eventer, Writer Veteran

    Messages:
    61
    Likes Received:
    9
    Location:
    A World Without End
    First Language:
    English
    Didn't work.

    But, I got an error this time instead: "Uninitialized constant Scene_System::SWITCHES"
     
    #3
  4. Venka

    Venka Veteran Veteran

    Messages:
    945
    Likes Received:
    360
    Location:
    United States
    First Language:
    English
    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
     
    Last edited by a moderator: Oct 13, 2014
    #4
  5. Halfmoon Media

    Halfmoon Media Illustrator, Eventer, Writer Veteran

    Messages:
    61
    Likes Received:
    9
    Location:
    A World Without End
    First Language:
    English
    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:
     
    #5
  6. Shaz

    Shaz Veteran Veteran

    Messages:
    36,911
    Likes Received:
    10,849
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    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.
     
    Last edited by a moderator: Oct 13, 2014
    #6
  7. Halfmoon Media

    Halfmoon Media Illustrator, Eventer, Writer Veteran

    Messages:
    61
    Likes Received:
    9
    Location:
    A World Without End
    First Language:
    English
    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

       @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"
     
    Last edited by a moderator: Oct 13, 2014
    #7
  8. Shaz

    Shaz Veteran Veteran

    Messages:
    36,911
    Likes Received:
    10,849
    Location:
    Australia
    First Language:
    English
    Primarily Uses:
    RMMV
    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.
     
    #8
  9. Halfmoon Media

    Halfmoon Media Illustrator, Eventer, Writer Veteran

    Messages:
    61
    Likes Received:
    9
    Location:
    A World Without End
    First Language:
    English
    ^^^^^Read edited post
     
    #9
  10. Halfmoon Media

    Halfmoon Media Illustrator, Eventer, Writer Veteran

    Messages:
    61
    Likes Received:
    9
    Location:
    A World Without End
    First Language:
    English
    *bump
     
    #10

Share This Page