Smarter Text+Choices Combining (Fix)

Hi guys, I'm surprised I couldn't find this already to be honest, maybe it's hidden somewhere... Anyway, I don't like to give you too much reading to do, so here goes:

Problem:

When an event shows text and immediately shows choices after it, the text remains visible (it persists until a choice has been made). The problem is when either the text or the choices are within a conditional branch, the text no longer persists (doesn't remain visible with the choices).

Request:

Make the text persistent through conditional branches and (optionally) comments.

Here's an example of how I might use it:

Conditional Branch: Switch[Player_met_person] == OFF Text: "Hi, can I help you?"Else Text: "Hello again, was I not clear?"Branch EndShow Choices: Who are you?, I need directions.... etc. ...In the above example, when the choices appear, the text should still be visible.

I hope it's not too challenging, unfortunately I don't know enough about RGSS3 to figure this one out myself, though I'll probably still try.
It can be done by script call.

if $game_switches[1]$game_variables[1] = "Hi, can I help you?"else$game_variables[1] = "Hello again, was I not clear?"endThen, in message box, you just put

\V[1]And then show the choices. I do not try it yet. But I'm sure it will works

Hope it helps ~
That would be great if this problem came up once or twice, but dozens of times, it just isn't worth it. Thanks, but I would much, much rather a script fix that will make text persistent than have to write this every time the problem arises.
It happens because the message system looks at the line immediately after the text and determines if it's a Show Choices, Number Input or ... something else that I'm not awake enough to remember. Since the line after the text in yours is either an Else or a Branch End, it fails, and shows the text on its own.

I encounter the same problem when I use Show Text first, followed by a Conditional Branch which determines what choices will be available.

Another way around it is something like this:

Code:
Conditional Branch: Switch[Player_met_person] == OFF    Text: "Hi, can I help you?"    Show Choices: Who are you?, I need directions.    When [Who are you?]      Jump to label: Who are you?    When [I need directions.]      Jump to label: I Need Directions    Branch EndElse    Text: "Hello again, was I not clear?"    Show Choices: Who are you?, I need directions.    When [Who are you?]      Jump to label: Who are you?    When [I need directions.]      Jump to label: I Need Directions    Branch EndBranch End# add an optional exit hereLabel: Who are you?  do stuff  Exit Event ProcessingLabel: I need directions.  do stuff  Exit Event Processing
I know why this happens, and I know the work arounds, but I'm still after a script fix for it. I'm sure it's possible, it just takes a bit of know-how with the window classes.

I will continue to look for a fix myself, but I don't know which classes to look in besides window_message.
It's not on the window classes. Look inside Game_Interpreter.

There are two cases that I can think of (probably more but anyway):

Conditionals: You need to know if the conditional "says" true or false and do the check accordingly.

Labels: This is easier, you just need to check the command after the place where the label is pointing to.

Also remember, there are conditionals inside conditionals, and COULD be labels after labels (pretty stupid but yeah why not?). You can make the check inside a loop until it stops getting conditionals (or labels, or whatever else).

Could be fun to do,

Orochii Zouveleki
Actually, you don't need any knowledge of the window classes at all. What you need is a good algorithm for scanning through the event commands and determining whether the text should be shown on its own or with something else. The "is the next line a Show Choices" command needs to be made more clever.


Game_Interpreter is where you need to be looking. Specifically, the command_101 method, which is Show Text. THAT is what currently determines whether the message box has an accompaniment or not.


If I were doing this, I would consider one of two approaches:


1. Make the logic in line 261 more clever - next_event_code looks at the code on the very next line, not taking into account whether it's a command to be run, or a non-executing line like a branch or branch end, or a comment. Consider ALL the times you might want the very next line to be ignored, or what are the valid lines that you DON'T want to be ignored, and add the logic there instead of using next_event_code. This could be tricky, as if the next line was a condition, you would need to evaluate that condition and check what's in the true/false statements to see if either one had a choices list and whether that'd be the one that's going to be executed (and that's just one thing you'd have to fine-tune for).


2. Let the method do everything it's meant to EXCEPT actually show the message. When the next 'real' command runs, see if there's a message to be shown, and if there is, decide whether the command waiting to be run needs to be tacked on to the message, or whether the message should be shown first, then to wait for the message to disappear, THEN run the command.


The first one would be more difficult to implement, but less invasive on the rest of Game_Interpreter. The second one would be easier to implement, and is probably the approach I would be more inclined to attempt.


It's actually a very interesting challenge, and if you really struggle with it, and I can get a decent amount of my own work done this weekend, I might be tempted to experiment a bit myself.


edit: oops - that reply wasn't there when I posted this. Can't believe it took me 20 minutes to type that up! Must have been distracted
I'd set a flag using a comment

Comment: Start Preserve textIf true show text "something"else show text "something else"endComment: End Preserve textshow choices: ...Or something of that nature. While the flag is set, everytime you get a "show text" you would store the text somewhere for later. The actual implementation is up to how you want to script it.This is an easy way to do it and gives event developers full control over it without any strange effects due to unforeseen cases.

I'd rather not try to solve the problems Shaz mentions.

When it comes to something like event commands, I would suggest providing tools that allows you to add functionality with additional markup, rather than modifying existing commands themselves where the only way to disable it is to disable it globally.
Okay, I did this, a little experimental but anyways. It solves the deal with conditionals and labels (and it supposedly deals with nested conditionals too).

Spoiler
class Game_Interpreter#--------------------------------------------------------------------------  # * Show Text  #--------------------------------------------------------------------------  def command_101    wait_for_message    $game_message.face_name = @params[0]    $game_message.face_index = @params[1]    $game_message.background = @params[2]    $game_message.position = @params[3]    while next_event_code == 401       # Text data      @index += 1      $game_message.add(@list[@index].parameters[0])    end    check_if_conditionals    case next_event_code    when 102  # Show Choices      @index += 1      setup_choices(@list[@index].parameters)    when 103  # Input Number      @index += 1      setup_num_input(@list[@index].parameters)    when 104  # Select Item      @index += 1      setup_item_choice(@list[@index].parameters)    end    wait_for_message  end   def check_if_conditionals    check_conditional(next_event_code)    check_if_conditionals if (next_event_code==111)||(next_event_code==119)  end   def check_conditional(code)    case code    when 111 # Conditional branch      @index += 1      execute_command      if (next_event_code==411)        @index += 1        execute_command        #print "|"+next_event_code.to_s+"|"      end      @indent += 1      return    when 119 # Jump to Label      @index += 1      execute_command      #@index += 1      return    end  endendAgain, it's experimental and probably badly coded. But it seems to work.
Other things that could be supported:

-Common events (call a choice from a common event, and the text from a regular lol map event).

-Behaviour commands like switch/localswitch/var/ operations and such

-Hidden commands, like "0", "412", etc.

Still, I see the original idea from theodoric MUCH more practical than this (and any other of the given ideas by others such as Shaz and Tsukihime), but I'm just getting some fun while meddling with Ace's scripts <3.

Again, fun,

OZ
But what if you have a few comments before the conditionals? Or if it's a Branch End after the text and not a conditional branch start?
Yeah well, there is a lot of cases in which that scriptlet doesn't works, but a lot of them are pretty easy to implement. For comments, you can just do a @index+=1. For any behaviour command (such as variable operations) you can raise one to the index, then do execute_command (this will execute the command before showing the message).

The most problematic part is managing the indent. When a command changes the indent (conditional branch start/end for example), you need to know what is the indent going to be, if not it will skip the entire branch (it's something that caused me several headaches while I was doing that scriptlet, until I put the @indent+=1 and voilà, everything works!).

I actually love the VXA event commands structure now because of this little exploration <3,

Orochii Zouveleki
The indent will always be @indent + 1, @indent, or @indent - 1, no exceptions.

There is always an "end" command to indicate the end of a block.

Code:
if  cmd  cmdend if
I think Tsukihime's toggle persist idea is good, and probably should be implemented as well, but I think if there are just conditional branches and label definitions in the way, it should persist anyway. It seems logical to me.

Muramasa, I will test your script shortly.

Edit: It works when the choices are within a conditional branch, but it doesn't work when the text is in a conditional branch and the choices are below it (which was my original requirement). Any ideas how to include this into your script?
Yeah, forgot about that lol. This might work, change the old method check_conditionals for this one:

def check_conditional(code)    case code    when 111 # Conditional branch      @index += 1      execute_command      if (next_event_code==411)        @index += 1        execute_command        #print "|"+next_event_code.to_s+"|"      end      @indent += 1      return    when 119 # Jump to Label      @index += 1      execute_command      #@index += 1      return    when 0 #close indent      @index += 1      #execute_command      @indent -= 1      if (next_event_code==411)        @index += 1        execute_command        #print "|"+next_event_code.to_s+"|"      end      if (next_event_code==412)        @index += 1        execute_command        #print "|"+next_event_code.to_s+"|"      end      return    end  endOr here is the full scriptlet:

Spoiler
class Game_Interpreter#--------------------------------------------------------------------------  # * Show Text  #--------------------------------------------------------------------------  def command_101    wait_for_message    $game_message.face_name = @params[0]    $game_message.face_index = @params[1]    $game_message.background = @params[2]    $game_message.position = @params[3]    while next_event_code == 401       # Text data      @index += 1      $game_message.add(@list[@index].parameters[0])    end    check_if_conditionals    case next_event_code    when 102  # Show Choices      @index += 1      setup_choices(@list[@index].parameters)    when 103  # Input Number      @index += 1      setup_num_input(@list[@index].parameters)    when 104  # Select Item      @index += 1      setup_item_choice(@list[@index].parameters)    end    wait_for_message  end   def check_if_conditionals    check_conditional(next_event_code)    check_if_conditionals if (next_event_code==111)||(next_event_code==119)  end   def check_conditional(code)    case code    when 111 # Conditional branch      @index += 1      execute_command      if (next_event_code==411)        @index += 1        execute_command        #print "|"+next_event_code.to_s+"|"      end      @indent += 1      return    when 119 # Jump to Label      @index += 1      execute_command      #@index += 1      return    when 0 #close indent      @index += 1      #execute_command      @indent -= 1      if (next_event_code==411)        @index += 1        execute_command        #print "|"+next_event_code.to_s+"|"      end      if (next_event_code==412)        @index += 1        execute_command        #print "|"+next_event_code.to_s+"|"      end      return    end  endend
It now checks for command 0, which is the end of a branch, and makes stuff accordingly.

That should work ~<3,

Orochii Zouveleki

PD.: I'm disliking how this scriptlet is growing, so I will probably do something about that, maybe just splitting that method into small methods.
Works 😀 . I have to say, the results look great.

Uhm, I'm curious, what is 412? I don't see it anywhere in Game_Interpreter.

Shortened version:  (Tested)

Spoiler
class Game_Interpreter #-------------------------------------------------------------------------- # * Show Text #-------------------------------------------------------------------------- def command_101 wait_for_message $game_message.face_name = @params[0] $game_message.face_index = @params[1] $game_message.background = @params[2] $game_message.position = @params[3] while next_event_code == 401 # Text data @index += 1 $game_message.add(@list[@index].parameters[0]) end while check_conditional(next_event_code); end #comment line to disable case next_event_code when 102 # Show Choices @index += 1 setup_choices(@list[@index].parameters) when 103 # Input Number @index += 1 setup_num_input(@list[@index].parameters) when 104 # Select Item @index += 1 setup_item_choice(@list[@index].parameters) end wait_for_message end def check_conditional(code) case code when 111 # Conditional Branch @index += 1 execute_command if (next_event_code==411) # Else @index += 1 execute_command end @indent += 1 return true when 0 # Close indent @index += 1 @indent -= 1 return true when 119, 411, 412 # Jump to Label, Else, Conditional Branch End @index += 1 execute_command return true end return false endend
Edit Added the last comment (thanks Shaz).
412 - Conditional Branch End
Would this script be worth adding to the Master Script list? Given a header explaining it of course.
If I have a voice on this, I don't mind. Credit to your heart's content, and throw whatever usage conditions you like (best if free for commercial and non-commercial ;D).

Asdf,

OZ
If you want it to be listed in the master script list, then you need to provide it as a properly formatted script in the VX Ace Scripts forum. Not as a response to a help request in a thread. Take a look at the thread that states what format they should be presented in - it's got a template that you can copy and paste and fill-in-the-blanks.
Added script topic.

Well I think this is solved so, thanks for the help everyone.

Original thread: https://forums.rpgmakerweb.com/threads/smarter-text-choices-combining-fix.18862/