How do I make a text box using slices?

From OHRRPGCE-Wiki
Jump to navigation Jump to search
Revise.png
This article does not meet the standard of quality we would like to have. Feel free to revise it and make it better by using the edit link at the top of the page. This tag should be removed when an editor feels it is of high quality.

The reason this article has been marked is: needs to be re-written for user-defined menus

We have seen in articles about strings that we could put dialogues in it. I recommand you read it before you come back here. Now we'll learn how to customize it.

This article will browse to all the main commands related to slice appearence. We'll use them along along with commands related to the key pressed by the player. What is the interest of all that you may ask? Well, we'll see that later in the conclusion.


Combined with a local variable and a slice[edit]

This is the most common way of doing it. To do so, we just need a free string and local variable. I recommend you to create a text file in the directory in which you store your game to keep a track of which strings are free and which aren't.

For example string_lists_MyRpg.txt. Here we are using string 5.

Edit your hss file and add the following scripts.

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

define script, NPC dialogue, none

#--------------------------------------------------------------
plotscript, NPC dialogue, begin

suspend npcs
suspend player

$5="Hello How are you?" 
show string at (5, 8, 15) )# give a position of the text
variable (npc dialogue box)
npc dialogue box:= create rect (280, 80, 0)
set slice width (npc dialogue box, 310)
set slice height (npc dialogue box, 45)
set rect trans (npc dialogue box, true)
set slice screen x (npc dialogue box, 5)# give a position to the fake text box
set slice screen y (npc dialogue box, 10)

wait for key (key: space) # very important. Allow the fake text box to disappear like the ones created with the text box menu.
if (key is pressed (key: space)) then, begin
free slice (npc dialogue box)  #make disappear the slice used for the text box
clear string(5)  #make disappear the text created through string.
wait (1)
end #end of the if key is pressed

resume npcs
resume player	
end# end of the script
#---------------------------------------------------------------

Go under custom. Edit the map menu. Edit the npc and make the NPC run this script. Test the game and go to speak to the NPC. If you want to lower your text box and your text raise the value which correspons to Y.

show string at (5, 8, 15) )# give a position of the text

-> change 15 to 30 or 45 to lower your text on screen

set slice screen y (npc dialogue box, 10)

-> change 15 to 30 or 45 to lower your textbox on screen

The best way to adjust things is to have at the same time your .hss file open in notepad.exe, and, custom.exe with your game testing. Change the numbers, save the hss file. Import it and make the script run by speaking to the NPCs several times.

If you want your text box not to be tranluscent just change the line to

  set rect trans (npc dialogue box, none)

Changing borders[edit]

Now you may want to change the borders of your fake text box.

a- Changing the line color of the box border[edit]

This method uses the


#--------------------------------------------------------------
plotscript, NPC dialogue, begin

suspend npcs
suspend player

$5="Hello How are you?" 
show string at (5, 8, 15) )# give a position of the text
variable (npc dialogue box)
npc dialogue box:= create rect (280, 80, 0)
set slice width (npc dialogue box, 310)
set slice height (npc dialogue box, 45)
set rect trans (npc dialogue box, true)

set rect bgcol (handle, color)
set rect fgcol (handle, color)
set rect border (handle, border) # color chosen is 

set slice screen x (npc dialogue box, 5)# give a position to the fake text box
set slice screen y (npc dialogue box, 10)

wait for key (key: space) #very important. Allow fake text box to disappear like the ones created with the text box menu.
if (key is pressed (key: space)) then, begin
free slice (npc dialogue box)  #make disappear the slice used for the text box
clear string(5)  #make disappear the text created through string.
wait (1)
end #end of the if key is pressed

resume npcs
resume player	
end# end of the script
#---------------------------------------------------------------

b- Changing the box border with box border sprites[edit]

Instead of a simple color line in harmony with the color of the foreground, you may want to use the text box border sprites that you edit in the graphics menu.

If so the command you need is the following :

 set rect raw border (handle, border)

Adding a portrait[edit]

Now you may want to add portrait on your fake text box just like the textbox menu options provides with the normal ones. As always the OHRRPGCE programmers have though about everything and created the commands you need for that.




Adding choices[edit]

Even fake text boxes can have choices. This time we'll add a menu with our fake text box.



Three text boxes at the same time[edit]

That's the main advantage of using fake text boxes. But you need to be careful because each fake text box consumes a free string.

Feel free to check the corresponding section of the article about how to make an Inn ? To learn more about this.



Conclusion[edit]

So after all those tests, what can we say? Creating text box using string and a local variable is bit more complicated than using the pre-defined function by when you know well your plotscript commands and if you copy-paste the ready to use examples above, it is really not a problem.

The main concern, as always is limitation: we have only 99 strings and 4095 variables whereas we have 32767 text boxes. So we need to be careful before occupying a string. Strings are very precious when you make your slice collections.

You can't give all the npcs of your game a individual script which a text boxe creating with rectangle slice like in the first example in this article. The script limitation will be reached so quickly that you won't be able to finish you game. If you want to use plenty of fake text boxes (for purposely selected Npcs), you need to use the switch command and a global variable as described in Fell free to read the "How do I make several npcs says something different later?"

So what is the main interest of creating text box through strings? Well the first answer is because it allows you to put on screen several text box at the same time as we have seen above.

Another reasons you may think off is because you want to make a game is several languages. Let's say you want to your game in spanish english and portuguese. You made a 4 hours long with let's 490 text boxes. But you have other 2 languages which means 1470 text boxes in totals.

Again the text box limitation is so high that it very unlikely to be a problem, but nonetheless it always a good thing to keep it in mind.


See also[edit]