quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Hello, all! I'm somewhat of a novice when it comes to scripts and forums and the like, so I'll try to be blunt.
I've been developing a VN (visual novel) type game with RPGMaker VX Ace, with Galv's visual choices and Yanfly's save engine. Working with existing scripts and patching some lines of code, I created a way to open the game menu while a message is on the screen. This part works flawlessly.
However, there is a dilemma with saving the game—specifically with a choice list window open. Message windows alone actually save and load just fine, but the game refuses to save when a choice dialog is open. I had a feeling I would run into a problem like this, but I have no clue where to start with scripting to get a save to work. I've browsed the system scripts myself, and can't seem to find what could be preventing the save from occurring. Any help would be appreciated.

Info I have so far:
I made the script console print each value of DataManager.make_save_header and .make_save_contents, as well as a "Save success/fail" file, and the result is that the save header is made with each value, but the save contents don't print anything except the "save fail" code.
 

gstv87

Regular
Regular
Joined
Oct 20, 2015
Messages
3,369
Reaction score
2,575
First Language
Spanish
Primarily Uses
RMVXA
and how can you save when having the choice window open?
usually for opening the menu you close the choice window first, and that defaults to the cancel branch.
 

quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
I created a script of my own to open the menu while choices are open. It doesn’t work unless the cancel option in the event is set to “disallow.” As mentioned, the menu opens just fine. The issue I need help with is with the save.
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,934
Reaction score
983
First Language
English
Primarily Uses
RMXP
Wouldn't it be easier to activate the autosave feature (speaking of a brand new feature here) than letting the player save during a choice window?
 

quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
I was unaware that RMVXA had autosave. That would technically work, but I’d prefer to have a method of players being able to save before making big decisions, so they can load if they aren’t sure of the result.
How would one go about activating the autosave feature?
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,934
Reaction score
983
First Language
English
Primarily Uses
RMXP
I meant, you'd have to implement a brand new feature, the autosaving of game sessions, even if that was not intended as an integral part of your project.
 

quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Oh, I see now. Well, in either case, I'd have to find out what is preventing the game from saving while a choice window is open. That's really the main issue I'm having—I'm sure activating an autosave while the window is open could also result in the same bug.
 

quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
After some continued research of my own into this issue, I fear that my problem could be related to an "incompatibility between Marshal (the code the game's save/load uses) and Fiber (the game's process for waiting for a message to type or, in this case, a choice to be called.)"
Unfortunately, I don't even know where to begin with scripting a fix for this, so I'm definitely in need of a lead. Any help appreciated.
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,934
Reaction score
983
First Language
English
Primarily Uses
RMXP
I truly suspect that we would need to see what changes you've made so far concerning the saving feature and messages. Otherwise we could easily end up telling you to overwrite some of your own code, invalidating some of its current features.
 

quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
I've tested with Galv's visual choices disabled and with Yanfly's save engine disabled, I'll link both just to be sure though.

My code for opening the menu is provided, I doubt it will be too closely related to the error, however, as it only opens the menu and allows for saving during the message window. The actual saving is done by Yanfly's engine, or in the case that I had it disabled, RPGMaker's script itself. The two are so closely similar that RPGMaker can actually read Yanfly's save files anyways.

My Message window menu code:


Yanfly's save engine:

Galv's VN Choices:

From my analysis, these scripts have nothing to do with the save not working. I could be wrong, but when I tested without both it still wouldn't let me save during choices. My goal is to allow it to work, either by fixing something in my scripts or by adding necessary code.
 

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,934
Reaction score
983
First Language
English
Primarily Uses
RMXP
My way of handling it would be to forget about displaying the choice window WHILE the menu scene is active on screen.

EDITED

The easiest way I could think off is to call the next menu as usual. This will allow you to keep the old scene paused or "not updated" while saving the game session. THEN before exiting the menu, you would need not to call the Scene_Map again, instead use SceneManager.return then.

And please don't double post. It's against the rules.
 

quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
I already have the key call the menu using SceneManager.call(scene), and I use the SceneManager.return method as well, I just overwrite it with an instant text enforcer so the message doesn’t start over typing out when the game is resumed and instead prints all at once, since that’s how it appears when the menu is called.
My issue, from what I can tell, is how to make the save method—which uses Marshal.dump()—compatible with the message system’s Fiber, or at least a way to save and resume its processing on command. I read in one of the comments of the DataManager module in the default scripts that “Marshal is incompatible with Fiber,” leading me to that conclusion.

Edit: Responding on my phone so if I misnamed a method I apologize
 

TheoAllen

Self-proclaimed jack of all trades
Regular
Joined
Mar 16, 2012
Messages
7,534
Reaction score
12,015
First Language
Indonesian
Primarily Uses
N/A
Out of curiosity, are you adding anything to the .make_save_contents or .make_save_header, like, saving the window itself?
 

quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
I have not tried that, actually, but I’m not sure how well it would work, since the message and choice window is a part of the Game_Map class, which is saved. I’m also only a novice when it comes to scripting, so I don’t even know where to begin.
I believe Yanfly’s engine, linked above, modifies the .make_save_header code so it can show more stuff on the save file in the menu, but that’s the only modification to that thus far.
What I’ve gathered is the game really shouldn’t be trying to save with the choice window open, so for now I’ll just modify part of the script I posted to disallow pausing the game while there are choices and add some kind of tell that the player should take their opportunity to save.
 

TheoAllen

Self-proclaimed jack of all trades
Regular
Joined
Mar 16, 2012
Messages
7,534
Reaction score
12,015
First Language
Indonesian
Primarily Uses
N/A
While your guess is on the spot about Marshal.dump not being compatible with Fiber or even Window/Sprite class, if you haven't changed anything about the save header/content, it can be ruled out.

Try this debug code.
Ruby:
#-------------------------------------------------------------------------------
# Save game no rescue
#-------------------------------------------------------------------------------
class Object
  alias :classname :class
end

class << DataManager
  def save_game(index)
    if try_saving
      return save_game_without_rescue(index)
    else
      return false
    end
  end
 
  def try_saving
    make_save_contents.each_value do |content|
      begin
        Marshal.dump(content)
      rescue
        msgbox "Failed to dump #{content.classname}"
        content.instance_variables.each do |ivar|
          var = content.instance_variable_get(ivar)
          puts "#{ivar} -- #{var.classname}"
          begin
            Marshal.dump(var)
          rescue
            msgbox "Failed to dump #{ivar}"
          end #-- Rescue
        end # -- Content instances each
        return false
      end # -- Rescue
    end # -- Content each
    return true
  end
end
This should give you an idea of which variable causes the problem instead of just "save fail"
 

quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Woah, that one gave me a lot more information. Thank you.
Two message boxes appeared, first was "Failed to dump Game_Message," followed by "Failed to dump @choice_proc." The console also prints a bunch of variables, some from my other scripts, which for some reason I previously deemed unrelated, which was likely a mistake.
I see "@choice_proc -- proc" in the console, I'm assuming that must be a variable and type which is incompatible with Marshal.
Edit: Knowing that, I need to find a way of either making it somehow saveable and loadable, or purge the variable in a way that can be restored when the menu is closed or the scene is loaded, in the same way that the message restores itself
 
Last edited:

kyonides

Reforged is laughable
Regular
Joined
Nov 17, 2019
Messages
1,934
Reaction score
983
First Language
English
Primarily Uses
RMXP
The Marshal class or module won't let you save a Proc object ever. So yeah, you do need to clear that variable and recreate it after Game_Message has been saved. Just assign that proc to an external variable beforehand, then set @choice_proc = nil and revert it after saving. You can use either a brand new global variable or you can create a new method in your Nox module like this:

Ruby:
module Nox
  extend self
  attr_accessor :temp_proc
end

Then you can call Nox.temp_proc and Nox.temp_proc = at any given time.
 

quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Will that work even across game sessions, I.e., closing the game and loading the save? If so, that’s perfect and it’s all I needed.
 

TheoAllen

Self-proclaimed jack of all trades
Regular
Joined
Mar 16, 2012
Messages
7,534
Reaction score
12,015
First Language
Indonesian
Primarily Uses
N/A
It probably won't. My idea would be to completely rewrite Proc to eval (as in, a string to be evaluated later) in Game_Interpreter. So instead of saving a proc, you save a string. Of course, the call OK handler and call cancel handler in Window_ChoiceList needs to be updated as well. Although what does the eval string look like, I haven't thought about it.

EDIT:
actually, the eval string might not work either hmmm

EDIT 2:
Within the assumption that you only ever use choice in the map (not in battle, or somewhere else like parallel event or parallel common event, because this code would make them unusable), you can try this.
Ruby:
class Game_Interpreter
  
  def setup_choices(params)
    params[0].each {|s| $game_message.choices.push(s) }
    $game_message.choice_cancel_type = params[1]
  end
  
  def choice_proc(n)
    @branch[@indent] = n
  end
  
end

class Game_Map
  attr_reader :interpreter
end

class Window_ChoiceList
  def call_ok_handler
    $game_map.interpreter.choice_proc(index)
    close
  end
  
  def call_cancel_handler
    $game_map.interpreter.choice_proc($game_message.choice_cancel_type - 1)
    close
  end
end
 
Last edited:

quantumxglitch

Villager
Member
Joined
Mar 20, 2022
Messages
12
Reaction score
1
First Language
English
Primarily Uses
RMVXA
Oh goodness, thank you so much! The patch works flawlessly, and it seems relatively simple as well. I'm able to save and load from an opened choice window perfectly! You're a lifesaver.

Edit: On second thought, I just tested loading the save. It opens the choice window as intended, but when an option is chosen it does not execute the branch.

Edit 2: After additional testing, I found that once a choice is confirmed after load, it simply closes out event processing completely. I'm looking into it to see what it could be doing. I forgot to save oops

Edit 3: I could be wrong, but I believe the branch and index aren't being saved. I'm not entirely sure how to go about doing that, and I'm open to suggestions. I'll try some experiments on my own in the meantime.
 
Last edited:

Latest Threads

Latest Posts

Latest Profile Posts

So in my SRPG, when kill monsters, they leave an aura that grants +20% Crit, +20% PDMG MDMG. Aura lasts only for 1 turn, it forces players when and where to last hit.

1702177938686.png
So frustrating when you just wanna work on your game but people want to do stuff in RL... :p
Day #9 of Advent is all ready in one spot! Do you prefer doing your shopping way before Xmas, or…do you like the chaos? Are you done shopping and/or crafting for Xmas?
Fast test with Wagon and horse no animation. yes it looks strange horse is Ralph and wagon is follower xDDDD
Should first boss be easy or maybe little medium, I don't want to be overwhelmingly hard

Forum statistics

Threads
136,887
Messages
1,271,056
Members
180,662
Latest member
funky-taco
Top