[SOLVED] Switch toggle via message?

Hi again, not sure if this is possible but I thought I'd ask around. Searching on multiple engines brought me nothing but 'how to use switches' and that's not what I need.

I'm using the Yanfly Message system, which has a few nifty codes in it to be able to change a few things as the message displays (EX. Changing text color /c[x], adding a name box /n<name>, writing an actor's name /n[name], etc.) Scripts also exist to animate text such as Tuckie's Text Effects (using /ani[x]). I was wondering if any scripts exist that could toggle a switch while a message is being written, for example you would write...

"Hi, it's me!" /switch[x] "Do you have any coins?"

...and it would toggle that switch mid-dialogue. Heck, even if there's a script that allows you to write a script call in the message system would work for me. I could swear something like that did exist, but if it does, search engines aren't bringing it to me.

I'm aware of the idea that the message window would prevent that from working-- And yes, that is usually the case. But when using the Yanfly Message system, waiting frames does allow switches to run in a parallel process (at least for me, it may be another script I have), so I don't think it's unrealistic.

Or, if anyone has an idea of a script call I could use to recreate something like that? Preferably the former, but I could probably find a way to get the latter to work.
"Hi, it's me!" /switch[x] "Do you have any coins?"
I don't understand what you are doing?
You can just simply show a message and in the next command change the switch.
Why does it have to be in the message?
The actual question here is why do you need to flip that switch right in the middle of that dialog. Isn't it enough to turn it on before or after the window closes? Or once a given text box finishes displaying the whole text.
The actual question here is why do you need to flip that switch right in the middle of that dialog. Isn't it enough to turn it on before or after the window closes? Or once a given text box finishes displaying the whole text.
It's for a visual gag that should occur mid-dialogue and it's clunky to have the message window/text disappear, reappear, and continue. Believe me I've tried to make it work for literally a whole year and I wouldn't ask about this if it was that simple.

If it's impossible, it's impossible. I just wanted to see if someone's managed to do it.
Here's my attempt at solving this unusual issue.

[It had a bug...]
Here's my attempt at solving this unusual issue.

Ruby:
# * The Switch Tag ACE * #
#   Scripter : Kyonides Arkanthes
#   2024-01-07

# The script implements the use of a game switch tag that looks something like
# this: \sw[10:on] or \sw[22:off]

class Window_Base
  alias :kyon_switch_tag_win_bs_conv_esc_char :convert_escape_characters
  def convert_escape_characters(text)
    result = kyon_switch_tag_win_bs_conv_esc_char(text)
    result.gsub!(/\esw[(\d+)\:(on|off)\]/i) do
      $game_switches[$1.to_i] = $2[/on/i] != nil
      ""
    end
    result
  end
end
I appreciate it-- However when I tried it, the engine has an error. It says line 12 ( result.gsub!(/\esw[(\d+)\🙁on|off)\]/i) do) is reaching a "premature end of char-class: /\esw[(\d+)\🙁on|off)\]/i"
I just missed a character.

Ruby:
# * The Switch Tag ACE * #
#   Scripter : Kyonides Arkanthes
#   2024-01-07

# The script implements the use of a game switch tag that looks something like
# this: \sw[10:on] or \sw[22:off]

class Window_Base
  alias :kyon_switch_tag_win_bs_conv_esc_char :convert_escape_characters
  def convert_escape_characters(text)
    result = kyon_switch_tag_win_bs_conv_esc_char(text)
    result.gsub!(/\esw\[(\d+):(on|off)\]/i) do
      $game_switches[$1.to_i] = $2[/on/i] != nil
      ""
    end
    result
  end
end
I just missed a character.

Ruby:
# * The Switch Tag ACE * #
#   Scripter : Kyonides Arkanthes
#   2024-01-07

# The script implements the use of a game switch tag that looks something like
# this: \sw[10:on] or \sw[22:off]

class Window_Base
  alias :kyon_switch_tag_win_bs_conv_esc_char :convert_escape_characters
  def convert_escape_characters(text)
    result = kyon_switch_tag_win_bs_conv_esc_char(text)
    result.gsub!(/\esw\[(\d+):(on|off)\]/i) do
      $game_switches[$1.to_i] = $2[/on/i] != nil
      ""
    end
    result
  end
end
Hmm okay, it does toggle the switch via the message window, but it turns the switch on right as the message window opens.
Fine. Here's the final version of my scriptlet.
Later on I'll replace it with a link to its own script thread.
Fine. Here's the final version of my scriptlet.
Later on I'll replace it with a link to its own script thread.

Ruby:
# * Switch Tags ACE * #
#   Scripter : Kyonides Arkanthes
#   2024-01-07

# The script implements the use of 2 game switch tags that look something like
# this: First \s[10] and later \+ or \-

class Window_Base
  alias :kyon_switch_tag_win_bs_conv_esc_char :convert_escape_characters
  def convert_escape_characters(text)
    @switch_block = Proc.new {}
    result = kyon_switch_tag_win_bs_conv_esc_char(text)
    result.gsub!(/\es\[(\d+)\]/i) do
      @switch_id = $1.to_i
      @switch_block = Proc.new {|state| $game_switches[@switch_id] = state }
      ""
    end
    result
  end

  def obtain_escape_code(text)
    text.slice!(/^[\+\-\$\.\|\^!><\{\}\\]|^[A-Z]+/i)
  end
end

class Window_Message
  alias :kyon_switch_tag_win_mess_proc_esc_char :process_escape_character
  def process_escape_character(code, text, pos)
    case code
    when '+'
      @switch_block.call(true)
    when '-'
      @switch_block.call(false)
    end
    kyon_switch_tag_win_mess_proc_esc_char(code, text, pos)
  end
end
IT WORKS thank you so much!!
This thread is closed due to being reported as solved. If you need it reopened, let us know. Thank you!

Original thread: https://forums.rpgmakerweb.com/threads/solved-switch-toggle-via-message.164581/