Activating command window from Map Scene

● ARCHIVED · READ-ONLY
Started by Mr. Trivel 8 posts View original ↗
  1. Let's say we have a random window which calls command window.

    class Random_Window_One < Window_Base def initialize() super(0, 0, Graphics.width, 200) @random_command_window = Random_Command_Window.new @random_command_window.start endendclass Random_Command_Window < Window_Command def initialize super(0, 200) deactivate set_handler:)one, method:)on_one)) set_handler:)two, method:)on_two)) end def on_one deactivate end def on_two deactivate end def start activate open refresh select(0) end def make_command_list add_command("Option One", :one) add_command("Option Two", :two) endend And creating it through event using

    @random_window = Random_Window_One.newThe window shows up properly, but it doesn't let the player choose between the options, it just stays there.

    You can even move away from the event.

    Spoiler
    Any ideas/tips how to do this properly?
  2. "deactivate" just deactivates the window. It dont change the openess of the window.

    You can use the method "close" to close the window and "open" to open it.

    *edit*

    So you want that the player cannot move anymore when the window is opened?
  3. Yes, since the player can move even if window is activated.

    Right now, if you activate the window, nothing happens. You can't move between the options or anything.
  4. Creating a window won't automatically allow you to interact with it. You'll need to call the "update" method on it every frame. Normally, the Scene classes handle this function, but since you're creating the window using an event call the Scene_Map class doesn't know the window exists and thus won't call update on it.
  5. This just isn't the proper way to handle a Window. If you offer why you are trying to do it this way, someone may be able to offer you a better or easier alternative (from what you have posted, I see no reason not to just use normal choice boxes from the built in message system) If you are just curious, thats fine too, this is the learning forum after all. You can handle Windows directly through events, but it is not recommended, especially if you not familiar with the basics.
  6. Mainly I was only interested, since it was easier just to make a new scene and do stuff there.
  7. Preface:

    I would highly recommend not handling a Window this way (as a instance variable within an instance of Game_Interpreter). Game_Interpreter objects are serialized into the save file, and this cannot happen if there is a Window object in an instance variable. You need to be absolutely sure you have both disposed all windows and nullified the containing variables before any kind of control is given to the player, or the scene is switched, or else the player will not be able to save the game. The initial example does neither - even if the window in the @random_window were disposed, you have left no path to get at the window in the instance variable in THAT window since it doesn't automatically dispose and you didn't leave an accessor. You should avoid nested window handling like this (window within a window) unless your second window specifically needs continual access to properties of the first; in this case, it doesn't, and the command window portion is encapsulated when it is the far more importation window of the two. Your handlers are also pointing back to the methods within window itself - and they both do the same thing.

    However, all that being said, this can still be done. First, trim the bloat out of your classes (I kept your naming conventions, but those could also use work):

    Spoiler
    class Random_Window_One < Window_Base def initialize() super(0, 0, Graphics.width, 200) endendclass Random_Command_Window < Window_Command def initialize super(0, 200) end def start activate select(0) end def make_command_list add_command("Option One", :one) add_command("Option Two", :two) endend
    In your event, create the windows and put them in instance variables*:

    @rw1 = Random_Window_One.new@rcw = Random_Command_Window.new@rcw.set_handler:)ok, proc { @my_var = @rcw.index } )@rcw.start*This should only be done in the main interpreter. Using a parallel process may cause you to lose your path to the window, which would be bad for reasons explained aboveThen, you need to loop and update at the bare minimum the command window. You also need a one frame wait in this loop so that the interpreter will yield back to the Scene, so the normal Scene update methods can take place (failing to do so will cause the loop to hang, since script commands do not cause the interpreter to yield, they will just continue through the local loop forever without allowing Graphics and Input to update). Since the interpreter is running (we are in the loop), the player will not be able to move or open the menu.

    Next, you need to conditionally break the loop. As you can see above, I have set the :ok handler to set an instance variable @my_var (again, terrible naming conventions, use something more appropriate) to a certain value. When the :ok handle is triggered, this proc will be activated and the variable will be set. So the condition for loop break can be that this variable is not nil. You can set separate handlers for each command, the :ok one will handle any one not specifically given a handler.

    As soon as you break the loop, you must dispose your windows and nullify their variables. For good measure, also nullify the other variable you have used, otherwise it will persist between event calls that use the main interpreter (you want the event to be reusable). This way, the next time you call this event, it will work normally.

    Throw it all together, you should have something like this:

  8. That was interesting and helpful.  Thank you!

    Is there any place that contains interesting information geared towards scripting?