Trigger Switches in Script

Halfmoon Media

Illustrator, Eventer, Writer
Veteran
Joined
Aug 17, 2014
Messages
61
Reaction score
9
First Language
English
Primarily Uses
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? 
 

Venka

Veteran
Veteran
Joined
Jun 20, 2012
Messages
945
Reaction score
365
First Language
English
Primarily Uses
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
 

Halfmoon Media

Illustrator, Eventer, Writer
Veteran
Joined
Aug 17, 2014
Messages
61
Reaction score
9
First Language
English
Primarily Uses
Didn't work.

But, I got an error this time instead: "Uninitialized constant Scene_System::SWITCHES"
 

Venka

Veteran
Veteran
Joined
Jun 20, 2012
Messages
945
Reaction score
365
First Language
English
Primarily Uses
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:

Halfmoon Media

Illustrator, Eventer, Writer
Veteran
Joined
Aug 17, 2014
Messages
61
Reaction score
9
First Language
English
Primarily Uses
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:
 

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,851
Reaction score
14,041
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:

Halfmoon Media

Illustrator, Eventer, Writer
Veteran
Joined
Aug 17, 2014
Messages
61
Reaction score
9
First Language
English
Primarily Uses
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

   @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:

Shaz

Global Moderators
Global Mod
Joined
Mar 2, 2012
Messages
40,851
Reaction score
14,041
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.
 

Halfmoon Media

Illustrator, Eventer, Writer
Veteran
Joined
Aug 17, 2014
Messages
61
Reaction score
9
First Language
English
Primarily Uses
^^^^^Read edited post
 

Latest Threads

Latest Posts

Latest Profile Posts

Today I drove through my city of 100,000+ people during rush hour and the streets were nearly empty. Just so I could go get my favorite burger. There a dental assistant (she said that's her other job, even though I didn't ask) took my order and handed me a burger. I know it's bad out there... But wow, she's either atrocious with her money, or "it really be like that".
Chilling out while toodling around someone's painstaking Minecraft recreation of Disneyland. It is mind-boggling and probably as close as I'll ever be to going.
>Testing with fonts change.
>Tries installing a plugin. Doesn't work.
>Tries changing the plugin commands. Doesn't work.
>Tries installing another plugin. Doesn't work.
>Changes a few more plugin commands. Doesn't work.
>Goes directly to the gamefont file and changes the src. Works.

YYEEEAAAAHHHAAAA

Perseverance is key, bois and girls.
What Reviews say on RPG Maker MZ?

Forum statistics

Threads
107,813
Messages
1,032,391
Members
139,957
Latest member
crowdmember2
Top