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

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
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

Veteran
Veteran
Joined
Mar 2, 2012
Messages
40,098
Reaction score
13,704
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
 

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

How many parameters is 'too many'??
Yay, now back in action Happy Christmas time, coming back!






Back in action to develop the indie game that has been long overdue... Final Fallacy. A game that keeps on giving! The development never ends as the developer thinks to be the smart cookie by coming back and beginning by saying... "Oh bother, this indie game has been long overdue..." How could one resist such? No-one c
So I was playing with filters and this looked interesting...

Versus the normal look...

Kind of gives a very different feel. :LZSexcite:
To whom ever person or persons who re-did the DS/DS+ asset packs for MV (as in, they are all 48x48, and not just x2 the pixel scale) .... THANK-YOU!!!!!!!!! XwwwwX

Forum statistics

Threads
105,853
Messages
1,016,990
Members
137,562
Latest member
tamedeathman
Top