How do I make choices in a dialog box?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

There are different to offer choices in a dialogue.

This article will focus on two choice question mainly known as yes/no question. If you want to give more that two choices chek the article about it.Feel free to ask questions on the forum if you have troubles implementing it


Using a text box and a tag[edit]

Okay. First, go into Edit Tag Names, pick an unused tag, and name it. For the sake of example I'll say tag 5 named "test choice"

The go into Edit Text Boxes and pick Edit Choice for the appropriate text box. First, set Choice=Enabled. Then name each of the options. In this case I will say option 0 is "Yes" and option 1 is "No"

Then you need to pick the tags that each option set. You can use any combination of tags you want, but the most common method is for one option to turn a tag ON, and the other option to turn the same tag OFF. make the "Yes" option turn ON tag 5 and make the "No" option turn OFF tag 5

Choose Edit conditionals. Pick up the last conditional will say:

  never do the following
    use [text box or script] next

Use the left and right arrow keys to change it to:

  If tag 5 = ON (test choice)
    jump to text box ? next
    # choose run script next if you want to launch plotscript and not a simply displaying a text box if the player chooses yes.

Then go up until the first conditional. You have

  never do the following
    use [text box or script] instead

Use the left and right arrow keys to change it to:

  If tag 5 = OFF (test choice)
    jump to text box ? instead #the text box number is the very same you're editing. If you're using text 21 put jump to text box21 instead


Now you may want to use plotscripting not only when the player chooses YES but also when he/she is choosing NO. In this situation you just have to edit slightly differently the conditionnals. So let's say that you want to displays a text whee the NPC feels insulted because the player refuses to do as thre NPC says. Jike like before, pick up a free tag and name yesno question (tag number is 21) Text box 150 will be the one included choice. Save your game.


Then go under windows, edit your.hss file and add the follwing script

script, NPC feels insulted, begin

if (check tag(tag:yesno question)==ON) then (
  show text box (154)
  wait for text box
), else, begin #do not change this line

  show text box (165) # Npc feel insulted
  wait for text box
  fight formation # fight a week monster
  show text box(169) # at least we obtain the information!
  wait for text box
)

end# end for the script


Import your script and edit the hss file (so that you can use your tag) Then, Edit text box 150. Write "would you like to do as I say?" As before, edit choices, write yes and no and make tag 21 turn on if the player chooses YES and turn off if the player chooses NO. Edit the conditionnals for text box 150 Go down to the last line

Use the left and right arrow keys to change it to:

    ALWAYS DO THE FOLLOWING NEXT
    run script npc feels insulted

This time you don't need to go back up. Why? because the script ALWAYS run next. The plotscprit lines for the yes choices and the one for the no choice are in the same script. Thanks to the tag, the interpreter always no which one to run. Give text box 150 to the right NPC and save you game and test the whole thing.

Last advice: be sure not to change the middle line. Don't create a "if (check tag(tag:yesno question)==ON)" and a "if (check tag(tag:yesno question)==OFF)" section in your script. Command lines and correct but you have very little time to run the command. It's easier for the interpreter to run straight the part script for what happens when the player chooses no from the "else" part instead of running it after checking first (because you tell him to do so) that tag value is OFF (after checking it was not ON). This way you script is kept light. If you have a large script, you can make slipt into sub script.

script, NPC feels insulted, begin

if (check tag(tag:yesno question)==ON) then (
  
   #launch your yes choice script from here

), else, begin #do not change this line

   #launch your no choice script from here

)

end# end for the script

Be sure no to re-use the tag for other things that yes/no choices, it may bug your game!

Using a slice, a string and a tag[edit]

You can also make text box using using a slice box, a string and a menu as yes:no function of the text box. Now how to? Well that rather easy.

Before we start : to make or fake text box wer'e going to use a slice and a string. We're going to use the slice function "create rectangle" and the string number 3

I strongly recommend to make a separate text file which serves as a string utilisation memo (especially if you are not used yet to strings).

Note that $3 is used to make display (and update dialogues). This way you won't forget it and use it somewhere else. That would make unwanted strange things may happen into your game because you forgot you're using a string which is used for another function.

The slice (= the fake text box) will manipulated with a global variable. Th example above is the most frequent (and yet vital) yes no question "would you like to save?"

Now let's go!

First go into custom. Creater a new menu. Name it choice menu or any other name which can help you to rember the purpose of the menu. In our example it will be menu (4). Give it two menu items yes and no (one item for yes and the other one for no)

Edit the menu bitset and make sure you hit the following ones.

allow gameplay and scripts
suspend player even if gameplay allowed
disable cancel button
prevent man menu activation
advance text box when menu closes

Go into the reposition section. Change the menu positon and make it go upward. (We want the menu be near the text box not in the middle of the screen as it is by default)

Then edit the tag menu and check that you have one tag dedicated to yes/no question. If not, create one. Call him yes no question or any other name that can help you to remember its purpose.

If you have done the section above, you can re-use the same tag.

This tag reserved to switch on and off when the player answer a yes/no question and should be use only for this purpose.

Edit your .hsi file dans save the changes. Leave custom

Open your hss file and pick a free global variable. Name it box or any other name which can help you to remember its purpose.

Then add the following scripts and save the hss file.

#----------------------------------------------------------------------------------------------

Global variable (12, box)	

#-------------------------------------------------------------------------------------------------

plotscript, Npc script, begin


$3= "Would you like to save?"
show string at (3, 10, 10)
box:= create rect (320, 35, 0) #1rst number witdh, 2nd number height, 3rd number style ( can take value ony from 0 to 14)

set rect trans (box, false)
open menu (4) # open yes no menu
wait (1)	 
end #end for the tag


end# end of the script
#-------------------------------------------------------------------------------------------------

plotscript, choice menu yes script, begin

if (check tag (tag:yesno question)==on)then, begin
suspend player
suspend NPCs

#menu 4 choice is closed through bitset fake text box disappear. no need to add close menu (4) line
free slice (box)  
clear string(3)
wait (3)
use shop (4) #shop 4 is save point

resume player 
resume npcs
end #end for the if check tag

end# end of the script
#-------------------------------------------------------------------------------------------------
plotscript, choice menu no script, begin

if (check tag (tag:yesno question)==off)then, begin

suspend player
suspend NPCs

#menu 4 choice is closed through bitset fake text box disappear. no need to add close menu (4) line
free slice (box)  
clear string(3)
wait (3)

resume player 
resume npcs
end #end for the if check tag

end# end of the script
#------------------------------------------------------------------------------------------------- 

Now yo can go back under custom.exe. Go into the edit shop section. Pick up shop n°4 and edit shop items and make it available save only. If shop (4) is already used in your game, create a new one do the same manipulation. Then change the number in the plotscript at the "use shop" line.

That's will make the script pop up the shop you need ^_^

Then go again into the edit menu. Then edit the menu items.

 Edit the choice menu. Edit the menu items.
 First the yes items: turn change to type 4 run script, then link it to the yes script choice.
 Edit the bitset and hit "close menu if selected"

Then, go to the no items: turn change to type 4 run script, then link it to the no script choice. Edit the bitset menu and hit "close menu if selected"

 Go back to the main menu. Edit the map and edit the npc. 
 Pick up the NPC you want to display the yes/no question
 Edit it and make it run "Npc script",.

You are ready to test.


Now why does this method is interesting?

Well because you can combine the string with a switch and among another thing). The script make savings on text boxes and scripts. At the beginning limitations are not a problem... but if you came to be passionate about your game you may want it rather long. Limitations then can become a problem! It's better to think ahead about limitations problems.

(See the section above for more details)

A yes no question adapted to different NPCS[edit]

You can also combine scripts, string and menu with string functions so that they display dialogue text accroding to various situations. You can create only one or two text boxes, but that you will use for tall your yes/no questions all along the game. Check below

See Also[edit]