How do I save up both text boxes and strings?

From OHRRPGCE-Wiki
Jump to navigation Jump to search

So you don't want to use plenty of variable and strings when updating dialogues and save text boxes in the long run? Well, you're in the right place.

In other articles we have seen how to update dialogue through strings. if you haven't read it, I suggest you do it before and come back to this one later. Now we're going to combine strings with the powerful switch command to use as less text boxes as possible.

The first method implies one a string, a variable and a text box, and, the second one: 2 strings and 2 variables.

This also will be the occasion to learn how to put a lot of text a string using the symbols n\


One string, a text box, and 1 variable[edit]

So go under custom and pick up a free text box. Put a string in it. (Just like you learned in the articles about updating dialogue through strings.) Here we chose string 9 and text box 14.

If you have not already done it, I recommend you create a simple text file called strings_list_mygame.txt to keep a track of which strings does what and which string is free as you develop your game.

Fianlly, check your map and be sure there is a NPC you can talk to and put in place. Then open your hss file and add the following scripts.

global variable (45, update dialogue)

#---------------------------------------------------------------------------
# test to learn how to save up both text bowes and string.
plotscript, test box and string saving version 2, begin

suspend npcs
suspend player
#string 9 is used for text

switch case (update dialogue) do, begin
case (0) do, begin
9$="When the demon lords awaken everyone \n was afraid and unwilling to fight \n but a group of courageous people started\n to think about a way to fight\n" # the symbols \n are used to divide into line inside a string
update dialogue:=1
end# end of case 1

case (1) do, begin
9$="So have you seen Mickael?\n Who?\n I though you were speaking about your brother\n" 
# the symbols \n are used to divide text into line inside a string
update dialogue:=0 # replace by update dialogue:=2 if you want to continue
end# end of case 0

# add following cases for further dialogue evolutions here

end#end of the switch

show text box (14) #text box 14 has string 9 in it 
wait for text box

resume npcs
resume player
end #end of the plotscript

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

Make this script run by a npc with the usual method. As you can see, we keep on poping up the same text box (text box14) with the same string in it over and over again. But, thanks to the switch function the text keeps changing. This is a very powerful saving method! Let's compare this with the second one below.

One strings, a slice, and 2 variables[edit]

With this method, the first thing you need to do is to choose a number between 0 & 99 for your string. (Again, if you have not already done, I recommend you create a simple text file called strings_list_mygame.txt to keep a track of which strings does what and which string is free as you develop your game.) for this example I chose string 3.

Check your map and be sure there is a NPC you can a talk to and put in place. Edit the hss file and add the follwing script.

global variable (45, update dialogue)

#---------------------------------------------------------------------------
# test to learn how to save up both text bowes and string.
plotscript, text box and string saving, begin

suspend npcs
suspend player

variable (fake box)
#string 3 is used  for text & and then displaying

switch case (update dialogue) do, begin

case (0) do, begin
3$="When the demon lords awaken everyone \n was afraid and unwilling to fight \n but a group of courageous people started\n to think about a way to fight\n" # the symbols \n are used to divide into line inside a string
update dialogue:=1
end# end of case 0

case (1) do, begin
3$="So have you seen Mickael?\n Who?\n I though you were speaking about your brother\n"  # the symbols \n are used to divide into line inside a string
update dialogue:=0
end# end of case 1
# add following cases here

end#end of the switch


fake box:= create rect (280, 80, 0)
set slice width (fake box, 310)
set slice height (fake box, 85)
set rect trans (fake box, true)
set slice screen x (fake box, 5)# give a position to the fake text box
set slice screen y (fake box, 10)
wait for all #wait that all previous is done before putting on screen
show string at (3, 8, 15)

wait for key (key: space) # very important. allow fake text box to disappear naturally
#delete the box created through strings
free slice (fake box)  
clear string (3)

resume npcs
resume player
end #end of the plotscript

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

As you can see, this method consumes no text boxes but requieres (a bit) more variables (2) and more strings (2).


Conclusion[edit]

So what to use? Well it depends on what you want to focus on saving. The first one seems at first to be more likely to fit your need because you can have 32767 text boxes whereas you have "only" 99 strings and 4095 global variables. So one may thinks that you're likely to run out of strings first and then eventually global variables.

But in reality, the second system is truly the most powerful. With only 2 variables, you have no need for the edit textbox menu anymore. Those 2 precious variables will be use over and over all along the game.

So if you have already made your own INN from scratch with a system with requiere to use fake text box and if you already use a global variable to udpate the dialogues of several npcs at the same, just use the second system.

The second system is recommended if you make your game in several languages, a situation where for the same plotscripting scenes the number of text box you need use raise very fast.


As always, if you have problems implementing this, feel free to ask for help on the forum or the discord group.

See also[edit]