[VX ACE] Show Choices through event (explained)?

Hello everybody.


I am trying to show more than four choices without implementing a built in script. In order to do this, i followed the precious instructions provided in this topic.


So, I put this script in an event:

Spoiler
@params = []
@choices = []
@choices.push("~ Back to Main Menu ~") # Fixed text.
counting = 6
for i in 1..$nameRegister.size - 6 
@choices.push($nameRegister[counting]) # I pus in the choices array the strings from my array from position 6 to the last one.
counting += 1
end
@params.push(@choices)
@params.push(1)
setup_choices(@params)


# Here is the problem. When I launch the game, all the code above works and the choices are correctly displayed, but, for every choice I select, the


# following code is not read and the choices window is closed like if, for every option there was nothing to do.


if @branch[@indent] == 0 


# Do nothing.
elseif @branch[@indent] > 0
# Do something.
end

 I suppose I totally misunderstood the instructions @Tsukihime provided here, and on YouTube, forums et cetera this particulare script call is not better explained.



So, what I am asking, for myself and for all the other developers who do not pleasantly fit in the four default choices, is: can anyone explain how to correctly call instructions for every single choice from a script-called choice list?

Thank you in advance 🙂
Can you give a screenshot of your event instead of retyping it here?


There are a few quirks of the script command in events that might cause problems here, or you might have made a simple type that you corrected in this rewrite or something like that, and a screenshot would show us those errors where retyping can't show them.
Here it is, Andar, but it is pretty long.

1.png

2.png

3.png

4.png

5.png
I think it is a problem with your definition of $saveFName


Please check this by adding a printf command inside the branch of the show choice check.


The script box is basically a sandbox and deletes all local content when the box is closed. If there is any mistake in the definition of $saveFName (which is the only result of the show choices), then that data will reset to zero on ending the script box. Only if that variable is correctly defined outside the script box and is allowed to receive data from inside the script box, only then that sequence will work.


By checking the variable before closing the script box, you can check if it does get the data locally or if the problem is somewhere else.
Just done as you suggested: I set the script to print $saveFName value before (after setup_choices(@params)) and after (at the end of the script) the last part of the script: the value is printed only when ordered before the second part of the script. I think that part is just not read.
Before or after the scene manager call? I suggest setting the printf directly before, because I think that command ends the script box and deletes the data if it is not correctly set to global
The scene call is not executed at all.
That is because you missed a very important part of that script call.

Spoiler
choices = [
"Choice 1", "Choice2", "Choice3", "Choice4", "Choice5", "Choice6"
]
cancel_id = 5
params = [choices,cancel_id]
setup_choices(params)
Fiber.yield while $game_message.choice? # <-- This is mandatory!
# Try to print the branch ID without the above line,
# and you will see why that line is needed.
p "branch id: #{@branch[@indent]}"
case @branch[@indent]
when cancel_id # When the cancel button is pressed this happens.
# Do cancel stuffs here.
else
# Do something else here.
end



You forgot to wait for the choice selection, therefore the branch indent was never properly set.


Add that line right after you call the setup_choices method and your code should work.


Also, do NOT set instance variables in event codes if you don't need to (and you don't need to for this)!


Especially don't use a built-in name for them! The @params instance variable you used is used by the built-in interpreter.


The @choices variable is not a built-in one, but in case a script would use it, and you overwrite it with your evented script call, you can cause problems in your game.


Just use local variables instead (without the @ sign before their name) for maximum compatibility.


And just to clarify...


Variables starting with a $ sign are global variables.


They are accessible from everywhere, in any class or module, even outside those. This includes the script box too, obviously.


The moment you create them from anywhere, they will be accessible from anywhere. This is the reason why it advised to not overdo with these things, because they are global, and if there would be 2 separate things created with the same name, the previous content of the global variable would be lost and overwritten by the data set to it later.
@Sixth, I just implemented your lines and it finely works! Thanks a lot for your help, guys 😀
It would be lovely if this compplete structure for custom choice list was added to the Script Call collection, so that everyone could use it.


Thank you again!

This thread is solved.

Original thread: https://forums.rpgmakerweb.com/threads/vx-ace-show-choices-through-event-explained.72358/