How do I update dialogue through slice collection?

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

number is the argument for the pressNumber script. For example, calling "pressNumber(15)" would make number = 15.
My pronouns are they/them
Ps. I love my wife
bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

Ok but...

Post by bis_senchi »

So it is a simple digit...

but then what should I put in the plotscript head ?
I need an number for an argument right?

You've also written string ID means, that's I'l need to pick up free string right. That
string will store the number which is going to be checked
bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

An answer please?

Post by bis_senchi »

KyleKrack, could you (you or somoene else) somoene else answer the question below?
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

Post by SwordPlay »

EDIT: I cleaned up the scripts somewhat, and you can choose your input mode and event more simply.
Attachments
numpad0006.gif
numpad0006.gif (62.96 KiB) Viewed 3300 times
Last edited by SwordPlay on Tue Feb 23, 2021 9:54 pm, edited 1 time in total.
"Imagination. Life is your creation."
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Re: Ok but...

Post by kylekrack »

bis_senchi wrote:So it is a simple digit...

but then what should I put in the plotscript head ?
I need an number for an argument right?

You've also written string ID means, that's I'l need to pick up free string right. That
string will store the number which is going to be checked
You do not need to change the script head. The pressnumber script should be called from a keypress handler script, like the one in the previous message. The input values are shown in this script:

Code: Select all

plotscript, keypress handler, begin
    if(keypress(key:1)) then(pressNumber(1))
    if(keypress(key:2)) then(pressNumber(2))
    if(keypress(key:3)) then(pressNumber(3))
    if(keypress(key:4)) then(pressNumber(4))
    if(keypress(key:5)) then(pressNumber(5))
    if(keypress(key:6)) then(pressNumber(6))
    if(keypress(key:7)) then(pressNumber(7))
    if(keypress(key:8)) then(pressNumber(8))
    if(keypress(key:9)) then(pressNumber(9))
    if(keypress(key:0)) then(pressNumber(0))
end
The arguments are in parentheses: "pressnumber(number)"
My pronouns are they/them
Ps. I love my wife
bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

Sorry but... I have another question

Post by bis_senchi »

Thanks to both of you SwordPlay and Kylekrack!

I'm making test and choose string 17 t receive the number which corresponds to the card.
The problem as it is nothing is recorded.

It launch the script and press on the keys. I've made given to an npc
a text box with string 17 in so that I can see what is recorded.


Before I start to work on sprite replacement to display the number entered I need to
be sure that keypress script works record data correctly.

The problem is the following: when the text box with string 17 in appear not figure appears


What could be the cause of this? May be I didn't use the right keys.... What numbers are you supposed to use? The one above the letters or or the one on the numpad?
As always thanks for the quick replays and your help!
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

Post by SwordPlay »

if you want more feedback, try taking a screenshot in CUSTOM with f12 to show us what is happening.

if you are using a textbox, you can display the contents of your string by typing "${v17}" in the textbox, i think?
Attachments
you can see how to embed codes below the textbox entry. Press F1 for more info.
you can see how to embed codes below the textbox entry. Press F1 for more info.
numpad0007.png (2.58 KiB) Viewed 3267 times
Last edited by SwordPlay on Wed Feb 24, 2021 7:58 pm, edited 1 time in total.
"Imagination. Life is your creation."
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Use "${S17}" to insert string 17, not V17.

The script uses "key:0", "key:1", etc, which are the keys at the top of the keyboard, not the numpad. (For numpad use "key:numpad 0", etc).

Sorry, I haven't been watching this thread, but I saw you were asking about how to write Spanish text in a script.
bis_senchi wrote: append ascii (10, 176) #ascii 176 177 et 178 are spanish writing specifics é,¿,Ñ
show string at (10, 10, 10)
append ascii (12, 177)
show string at (12, 20, 10)
append ascii (13, 178)
show string at (13, 30, 10)
bis_senchi wrote:if I write
$3= "Hola ¿Que Tal?" the buffer won't work correctly.
The answer is that you go to Edit Font and select "Font type: Latin1". You need to lay out your font to match the Latin-1 codepage, also seen in the attached screenshot, which is the default OHRRPGCE font (available in import/fonts/OHRRPGCE Default.ohf; import/fonts/Latin-1.ohf also has all these characters but not the RPG icons). I guess you started your game years ago before the default font was changed to this.

(Warning: the font editor shows 14 characters per row, but when Latin-1 is shown as a grid on website it's always 16 characters a row.)

For example é, ¿, Ñ are characters 233, 191, 209, not 176, 177, 178 as in your font.

After doing that, you can now write $3= "Hola ¿Que Tal?" in your script, and type letters like Ñ directly into Custom using your keyboard.

In future I plan to add Unicode support to the OHR. If full Unicode support takes too long I am also thinking of supporting codepages other than Latin-1. In particular, several people asked me to add Cyrillic and Katakana + Hiragana codepages.
Attachments
latin1.png
latin1.png (5.75 KiB) Viewed 3239 times
Last edited by TMC on Thu Feb 25, 2021 2:38 pm, edited 6 times in total.
bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

As requested here are scripts

Post by bis_senchi »

Thanks TMC for your answer both here and on the wiki. I managed to solve my problem two weeks ago.

The command I was needing was append ascii. As you pointed out, the value you need depends on your game font table. For example é, ¿, Ñ are characters 233, 191, 209 would be the value I need if I had not rearrange my font table. I've completed the article "How do I use string to update dialogues?" So that other game makers can see the various ways to tackle this problem.

I'm not tackling with issues linked to number imput and large number storage.

Anyway, for Kylekrack and Swordplay. Here are the screenshots

Image
Image
Image

Shouldn't I use a global variable to store my digit? After all, It's not only a digit but on that can change greatly all along the game. :???: Strings are mainly used for the text but you can make appear a figure through string, if you use text box line and if in the line there is something like ${v32}.

As always thanks in advance for the help
Last edited by bis_senchi on Fri Feb 26, 2021 5:58 am, edited 1 time in total.
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Re: As requested here are scripts

Post by TMC »

bis_senchi wrote:I've completed the article "How do I use string to update dialogues?" So that other game makers can see the various ways to tackle this problem.
Oh OK, I didn't see in that article that you'd figured it out yourself.

The article is long and tries to explain how to do many different things, but some of them are things that people should not do! I could say both that you are wasting your time with those examples, and that you shouldn't waste the reader's time with unhelpful examples.

It seems that you're trying to translate your game to multiple languages but your font is mixed up, and you wrote an article about what you learnt? I think what you should do is reorder your font to the Latin-1 layout and export all your textboxes to a .txt file. Then use search-and-replace in a text editor to replace the characters that appear wrong with the correct ones, and reimport your textboxes. Then you need to manually fix the letters used in all the other text in the game. (And of course, make a backup of your game first!)

Aside from that, it looks like a tutorial for how to add symbols/text in a script or in a textbox when you can't simply type it. That's useful to know but should just be a separate short article.

I know that translating an OHR game is a huge task because the engine doesn't help at all. I am actually working on translations as a builtin feature. How it works is that there is an option to export all the text in your game to a .txt file which you translate, then import it. The engine keeps the translations separate (so nothing changes in the .rpg file) but the player can switch between languages using a menu. Then if the player opens a textbox, for example, the engine gets the translated version of the textbox from the translations.txt file instead of the normal textbox contents.


Actually, there is another way to add characters to strings which is not well known.
If you select character 175 in the font it says "Char 175/U+00AF" at the bottom. You can add this character to a string in a script using the \xAF code. \x (x stands for 'hexidecimal') must always be followed by two hexidecimal digits. So to add characters 175, 176, 177 to a string you write:

Code: Select all

$10 = "Sec\xAF\xB0o Bu\xB1en"  # "Secção Bußen"
BTW, in the script

Code: Select all

portuguese letter1:= append ascii (10, 83) #string 10 is for appending ascii characters and var
portuguese letter2:= append ascii (10, 101)
#etc
the variables "portuguese letter1" etc are useless.

Code: Select all

wait (3) #waite som ticks to be sure all letters are added correctly into the string
You should not use a wait here, it is useless. All script commands take effect immediately, except when they are before a "fade screen in/out" (or something that causes a screen fade, like "fight formation").

Also instead of

Code: Select all

wait for key (key: space)
if (key is pressed (key: space)) then, begin
   ...
end
The "if" is pointless. And maybe you would prefer check all "use" keys, not just space. Then write

Code: Select all

wait for key (use key)
...

Anyway, for your current problem, can you please post your scripts for the card machine?
Shouldn't I use a global variable to store my digit?
You could store the number the player inputted either as a string (as kylekrack's script does) or as a number. I think using a string is slightly easier.

Then you convert the string to a number using the "number from string" command. For example.

If it's a number you would do something like

Code: Select all

plotscript, card machine, begin

  if (pay money(1000) == false) then, begin
    show text box (55) # Not enough money
    wait for text box
  end

  variable(collection, code)
  collection := load slice collection (8)
  clear string (17)
  # The script for getting the code from the player goes here ...

  free slice (collection)

  code := number from string (17)  
  
  switch (code) do (
    case (89631139)  #Blue Eyes White Dragon
      show textbox (100)  # Whatever you want to do here
    case (15025844)  #Mystical Elf
      show textbox (101)
   #etc
   )
end
Last edited by TMC on Sun Feb 28, 2021 4:08 pm, edited 3 times in total.
bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

Here are the scripts

Post by bis_senchi »

As you requested, here are the actual versions of my script

Code: Select all

#------------------------------------------------------------------------------------------
#script for keyboard customisation
plotscript, mykeypressedscript, begin



if (check tag (tag: card machine is used)==on) then, begin #key implementation for card machine

    if(keypress(key:1)) then(pressNumber(1))
    if(keypress(key:2)) then(pressNumber(2))
    if(keypress(key:3)) then(pressNumber(3))
    if(keypress(key:4)) then(pressNumber(4))
    if(keypress(key:5)) then(pressNumber(5))
    if(keypress(key:6)) then(pressNumber(6))
    if(keypress(key:7)) then(pressNumber(7))
    if(keypress(key:8)) then(pressNumber(8))
    if(keypress(key:9)) then(pressNumber(9))
    if(keypress(key:0)) then(pressNumber(0)) 

end #end for the if check tag
#------------------------------------------------------------------------------
# script which adapt to all yes/no questions in the game using a real text box
plotscript, yes no question script system 1, begin


suspend player
suspend npcs

switch (choice menu with text box option) do, begin

case (0) do, begin #choice menu with text box option:=0 is for car game machine

if (check tag (tag: Yes No Question)==on) then, begin
put card machine version two on screen
end# end for the if check tag


end #end for the case
end #end for the switch

resume player
resume npcs

end #end for the script
#---------------------------------------------------------------------------------


script, put card machine version two on screen, begin

suspend player
suspend npcs

if (pay money(1000)) then, begin

set variable (my money, party money) #put own money amount up to date on status menu
set tag (tag: card machine is used, on)
slicehandle:= load slice collection (8)

wait for key (key: space)
if (key is pressed (key: space)) then, begin
free slice (slicehandle)
set tag (tag: card machine is used, off)
wait (5)
exit script
end #end of if keypress


end, else, begin #if not enough money display text box 147: sorry not enough money
show text box (147)
wait for text box

resume player
resume npcs
end #end for the if


end #end of the script
#------------------------------------------------------------------------------------
To finish here are some screenshots

First a shot from the Game Boy Advanced game
Image

And then my attempt to re-crete it.
Image

So, how do it work? well after paying 1000 yens/$ the card game machine appears on screen. The arrows controls are changed to that when you move a different figure is selected.
You press a key in the game boy advanced it's the b button, but I chose the d key.
The selected figure appear on the upper part. In my case it's the figures in the red rectangle.

Finally you press ok. The 8 figure number recorded by the script is compared with the re- recorded list. If the digits correspond, the user gets the card which corresponds to the number he keys in in the machine, else, he lost money.

The first things I need to tackle (I think) is how to record key values... and like them to the correct sprite...

Quite a challenge isn't it! Anyway, all script modifications and suggestion of improvement are welcomed!
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I haven't looked at Swordplay's scripts. But there's nothing in your scripts that looks like the system he scripted. Aren't you using them? It looks like you want to use them instead of kylekrack's pressNumber script.
It looks like you intend the on-keypress script to listen for keypresses, update the slice collection, and put the number in a string or global variable, until "wait for key (key: space)" continues, right?
Last edited by TMC on Mon Mar 01, 2021 9:37 am, edited 1 time in total.
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

Re: Here are the scripts

Post by SwordPlay »

bis_senchi wrote: ...
The first things I need to tackle (I think) is how to record key values... and like them to the correct sprite...
Sounds like a good plan. You mean link?

Here is a hint for loading sprites, and getting the digit from them.
The sprite set or frame numbers can match the digits they represent.

Example: digit sprites for 0 to 9 are in sprite frames 0 to 9
If you have sprite frame 7, you have the digit 7
And if you want to get the sprite for digit 7, you load sprite frame 7
You can use the sprite set number or frame for this.

You can also add an offset.
Like if sprite 41-50 are the digits "0 to 9"
Then if you want the sprite for digit 7 you load sprite 7+41

We can also do this with slices, for example with slice children.

If you want to check each number 0 to 9, you can use a loop.
This will work for sprites, slices and digits.

for(i,0,9,1)do(
IF(currently selected==i)THEN(load sprite set(i))
)

this will load sprite of digit stored in variable or returned by script "currently selected"
you need a way to get the current selection!
you can do this as a script.

based on bis senchi's slice collection. please move the cm0 key above the other cm keys in the slice tree

store the direct parent of cm keys in a variable. you can use "slice child()"

then you check each cm key with a loop
if cm key 0 is first(1st) child, it is slice child 0.
cm key 9 is tenth(10th) child, it is slice child 9
(because slice children are numbered from 0)
so we can do this:

for(i,0,9,1)do(
if(selected(slice child(target,i))then(return(i))
)
# here "target" is the parent of the cm key slices

"selected" represents the selection method.
example is up/down/left/right keys to move a cursor, or mouse clicking.
you can display the cursor over the keys, and check with "slice collide()" to return the digit from the slice child number.
When the cursor is on cm key 4, it will return the number 4, for example.
the cursor can be an arrow, or rectangle, highlighting effect.
as long as it collides with the cm key we can check which cm key it collides with, and return this digit.
Last edited by SwordPlay on Tue Mar 02, 2021 4:19 am, edited 3 times in total.
"Imagination. Life is your creation."
bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

ok but...

Post by bis_senchi »

Sword play wrote
The sprite set or frame numbers can match the digits they represent.
Example: digit sprites for 0 to 9 are in sprite frames 0 to 9
If you have sprite frame 7, you have the digit 7
Well that works only if I chose to use border sprite but I wanted bigger
digits so I chose weapon attack graphics, which as you know is only one frame.
But in some other situations it may work.

Conserdering using slice children, as each sprite as to manipulated
individually quite a lot I think I'll keep the look up code at least for the digit used for
keying in the card number code.

I don't see each time search for chidren instead of a simple slice lookup

But after reflexion, I may use slice children for the digit on the red rectangle...

Those lines of code seems to be a good start.
But in what script should I put them? The first line make appears the digit according
one the red rectangle (the upper part of the mchine) according to the one we selected
on the blue rectangle (the bottom part of the machine).

Code: Select all

for(i,0,9,1)do(
IF(currently selected==i)THEN(load sprite set(i))
) 
What does the following lines do?

Code: Select all

for(i,0,9,1)do(
if(selected(slice child(target,i))then(return(i))
)
# h

What should happen to the key pressed script? As the player valid figure with the D key and use keyboard arrows to move on the num pad, I need to change it too

Code: Select all

#------------------------------------------------------------------------------------------
#script for keyboard customisation
plotscript, mykeypressedscript, begin

#key implementation for card machine. Arrows used for moving on the numpad 
#and d for validation of a figure and then the whole 8 digit card number

if (check tag (tag: card machine is used)==on) then, begin 

    if(keypress(key:up)) then ???)
    if(keypress(key:down)) then ??)
    if(keypress(key:left)) then ??)
    if(keypress(key:right)) then??)

    if(keypress(key:d)) then ??) 
    #d is used for validation process 1- first valid chosen digit
    #2- if the ok key is pressed with d then the whole card number verification process begin

end #end for the if check tag 
end #end for the script
#-------------------------------------------------------------------------

As always thanks for your Swordplay, KyleKrack and TMC for your answers and numerous pieces of advise...
Last edited by bis_senchi on Tue Mar 02, 2021 5:30 am, edited 2 times in total.
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

Post by SwordPlay »

are you using the latest version of the engine?
you can change the dimensions of any spriteset freely.

Regarding using sprite frame...
if the sprite has only 1 frame, you can use multiple sprites, and use their "sprite set number" instead of "sprite frame".
I don't see each time search for chidren instead of a simple slice lookup
Good point. You could just get the colliding digit and send a copy of it to the red box/digit display.
What does the following lines do?
This could for example, check when a number has been pressed, and return it as the selection.
e.g, it could check for player input and set "currently selected" for the previous script
What should happen to the key pressed script? As the player valid figure with the D key and use keyboard arrows to move on the num pad, I need to change it too
looks okay. you can do it in lots of ways.
you probably want to have a sprite cursor. maybe a rectangle going around the digit sprite.
you need to run your checks in a loop (probably)

...Input Checking
there are only 2 or 3 main parts to input checking
1. if the directional keys are pressed, the cursor moves around.
2. when the validation key is pressed you need to get the current digit, and display a sprite in the red box
3. if the ok key is validated or the digits reach their limit: end your checks for player input... break out of the loop.

another way to handle input checking is with a listener.
example: input with mouse click.
to do this: in a loop, you can check which digit is currently colliding with a mouse cursor, and store it in a variable.
there is a check for mouse click. when mouse click is activated it passes this variable.
this variable can return number keys and OK key, and maybe an invalid state when no key is selected by mouse
When this variable is a number key, we display appropriate sprite in red box.
When this variable is the OK key or digits limit are reached, we end the loop.
When this variable is an invalid state, because no digit is selected with mouse, nothing happens.

...Ending the input check.
1. you need a check "if digits limit are reached". you can do this in your loop, or everytime a digit is entered.
2. you also need a check "if OK key is validated".
in these cases, you end the loop which checks for input, and pass the input number.

...Running the Loop
change the "IF(tag)THEN(" in your script, to "WHILE(tag)DO(" and it will become a loop.

If you turn this tag off, then the loop will end.
You can also use "break" to exit a loop.
Add a "wait" in the main body of the loop, or else it will crash! (lol).
This "wait" causes the instructions in the loop to be run every tick.
"wait" is the same as "wait(1)", actually we can use any number to slow down the script.
Last edited by SwordPlay on Tue Mar 02, 2021 11:45 pm, edited 4 times in total.
"Imagination. Life is your creation."
Post Reply