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

bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

How do I update dialogue through slice collection?

Post by bis_senchi »

Hello!
I have a question about slice collection more precisely sprite manipulation through slice collection

Here is my problem

Image

I've made a container for text box. The hero portrait is sprite with a look up.
The characters are also sprite (box edge sprite)

The text box would appear and disappear using the slice collection command.
So far so good. The problem comes from when I want to update the content of the text box.

As you can see above I've made a three line text box
Each sprite has to be able to be updated individually. Because a sprite � may become a �. And then, in the next playseen, may need to become a � or a � depending its place on the sentence.

However, the whole content of the text box (the 3 lines sentences) have to be loaded/ unloaded in one time. I was thinking about using the option called "visible". Could someone tell me how to turn a slice collection element visible/ invisible through plotscripting?
Is there a command for this?

Another concern is about the look up slice code.
While invisible, I need change all the characters slices one by one. If I need a look up slices for each one of my japanese letters I may overuse them and I've not finished all the game implemenation yet I would like to prevent that.

Is there a way to make a single slice look up code ("dialogue update") (or another thing) do the trick by putting it in a loop which would check each slice collection element used a sprite and would also change the value / the sprite appearance for the coming piece of dialogue?


As always thanks a lot in advance for your help!
Last edited by bis_senchi on Mon Jan 25, 2021 11:16 am, edited 2 times in total.
ArtimusBena
Slime Knight
Posts: 251
Joined: Thu Nov 16, 2017 5:22 am

Post by ArtimusBena »

Whew, that seems like quite the task.

So, to keep track of a slice collection outside of just one script you'll have to introduce it with a global variable as a handle:

global variable (id#, mycollection)
mycollection := load slice collection (collectionid#)



Then to make it visible or invisible:

set slice visible (mycollection, true) or
set slice visible (mycollection, false)


You can also give it a lookup (I believe) with the command:

set slice lookup (mycollection, sli:mycollectionlookup)
Last edited by ArtimusBena on Mon Jan 25, 2021 8:25 pm, edited 1 time in total.
Do you make love with the same urgency you make games?
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

Good lord, I think what will really help you loop through the characters is making them all the child of a new container (or grid). If your collection looks like this:

Code: Select all

Rectangle
Container
   Grid
      Sprite
      Sprite
      Sprite
      ...
   Sprite hero portrait
Then you can loop through all of the children of the Grid slice, either using a for loop or a while loop

Code: Select all

variable(child)
# for loop
for(child, 0, childCount(firstGridChild(firstContainerChild(collectionHandle)))--1) do(
    # Change character
)
# while loop
child := firstChild(firstGridChild(firstContainerChild(collectionHandle)))
while(child) do(
    # Change character
    child := nextSibling(child)
)
Using a grid would also automatically position the characters for you, as long as each character sprite is a child of the grid slice.

You can set a sprite invisible by using "setSliceVisible(handle, false)" and make it visible again by using "setSliceVisible(handle, true)".

The rest of your question seems too complex for me to be able to answer accurately. Does any of this help?

Edit: Bena was faster than me so I didn't see his reply until I'd submitted mine
Last edited by kylekrack on Mon Jan 25, 2021 8:29 pm, edited 1 time in total.
My pronouns are they/them
Ps. I love my wife
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

Post by SwordPlay »

Wow that sounds very cool!

how are you scripting this?

It wouldn't be too hard to have a system where you type in Romaji, and have codes that convert it to Hiragana Katakana or Kanji.

I can show or make an example if you like.

You wouldn't need lookup codes for each letter either, if that is what you are asking.
Last edited by SwordPlay on Mon Jan 25, 2021 11:01 pm, edited 1 time in total.
"Imagination. Life is your creation."
bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

Thanks for all your pieces of advice!

Post by bis_senchi »

Ok, I've made some work on my collection.

I created a grid and change the place of the hero portrait sprite in the collection

Image

Image

Image

set slice visible(handle, true) is very useful and seems to be what I need to clear the text box.
But before that I need to understand why only the last 4 of characters sprite appears.
Each of them are visible so. As you an see above, I've edited the slice collection element and there are no main difference.

I suspect that the problem come from order of the element in the collection but can't figure where the problem is exactly :???: Does anybody has a idea as to why that is?

My characters grid is going to be 15 rows *3 lines which make a total of 45. As I had foresceen, I need be able to manipulate each of them individually to give the correct appearance, one after another. Giving each one a individual look up slice would allow me to that, but if possible, I would like to do it otherwise and save 45 slice look up code.

Anyway thanks to kylekrack and sword play for their answer.
Last edited by bis_senchi on Tue Jan 26, 2021 7:34 am, edited 1 time in total.
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

I can't think of why they wouldn't be visible while some others are. Maybe the grid slice is clipping children? That wouldn't really make sense but who knows.

You do not need to add lookup codes. All of the character sprites are children of one slice, sequentially. You can iterate through each child of the grid slice, one at a time, and make the changes.

Code: Select all

variable(n, character)

for(n, 0, childCount(grid)--1) do(
    # in each loop, n will increase by 1
    # figure out "character" here
    setSpriteSetNumber(sliceChild(grid, n), character)    # change the nth child of the grid
)
Does that make sense? I tried to comment it better.
Last edited by kylekrack on Tue Jan 26, 2021 8:03 am, edited 1 time in total.
My pronouns are they/them
Ps. I love my wife
bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

Does that make sens? -> well, not completely

Post by bis_senchi »

I found the problem. My grid element was clipping children. Therefor, I could see only a
part of the character elements. I change that and put the characters back in the right place
and it is really much better.

Image

You also said that we don't need to use tons of look up code. Which is great. That's the
kind of solution I'm searching for. For a first, let's say I want to change/ alter the sprite set of the 3 characters I put in grey. How should I proceed?

How do I know which child number had been given to them?
replace sprite (slice, sprite type, num, palette) and/or replace border sprite (handle, num, palette) seems to be the command I need but you didn't use them in your piece of code.
How come?

Thanks again kylecrack for all those pieces of advice and for answering so quickly.
Last edited by bis_senchi on Wed Jan 27, 2021 6:18 am, edited 4 times in total.
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

Child index starts at zero, so the first child would be "sliceChild(grid, 0)"

The grayed out sprites would be children 2, 3, and 4.

You don't need to use replace sprite unless you're changing which type of sprite it is, eg. a walkabout or a small enemy sprite. "set sprite set number" will just change the spriteset. If you also need to change the palette you can use "set sprite palette."
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, Im completely lost T_T

Post by bis_senchi »

I've made some attempts but I couldn't do it.
I've also not mentionned yet that for space saving issues, I'll also use frame and not only palette set (and sometimes both). So I'll need the command set sprite frame (handle, num)

For the moment I would like to make a simple attempt but trying to change only two characters.

Slice child nb2 in the grid would change its palette to palette Nb5
Slice child nb3 in the grid would change its frame to frame nb 6

Code: Select all

#---------------------------------------------------------------
#Script to test dialogue update through slice collection
plotscript, test foreign language implementation, begin

suspend player 
suspend npcs

show text box (124) #Npc: This a test for dialogue implementation in japanese
wait for text box
wait (4)
menu handle:= load slice collection (5) 
# dialogue box slice collection. Screenshot in previous spots

wait (15)

variable (n, character)

for(n, 0, childCount(grid)--1) do(
    # in each loop, n will increase by 1
    # figure out "character" here
    setSpriteSetNumber(sliceChild(grid, n), character)    # change the nth child of the grid 

resume player
resume npcs

end #end of the script 
#------------------------------------------------------------
Could you please complete the code above with those changes so that I can see more concretely how plotscript commands works together?
I've included the line you put in your last post.

Thanks again and have a nice day!
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

You're going to need to rework the loop I wrote to use the variables that you've created. First of all, 'grid' is never defined. Change 'variable(n, character)' > 'variable(n, character, grid)', then add the line 'grid := first grid slice(menu handle)'. This will set 'grid' equal to the slice handle for the actual grid slice on your slice collection.

Next, the variable 'character' is doing nothing. It's never set to anything, so it's always equal to 0 in this script. The line that says "# figure out 'character' here" is where you need to determine which character you need to change to. I do not know how you intend to do that.

Getting which set/frame you need to change to is going to be very complicated. I recommend creating a separate script for this. You can use a switch statement and just write out all of the possibilities, sort of like this:

Code: Select all

script, set new character, handle, character, begin
    # handle = slice handle for sprite we're altering
    # character = value that represents a symbol
    switch(character) do(
        case(0) replace sprite(handle, [SPRITETYPE], 0, [PALETTE]), set sprite frame(handle, 0)
        case(1) replace sprite(handle, [SPRITETYPE], 0, [PALETTE]), set sprite frame(handle, 1)
        # Repeat for each possible character
    )
end
Then you can call this new script from the original.

Code: Select all

variable(n, character, grid)
grid := first grid slice(menu handle)

for(n, 0, child count(grid)--1) do(
    # in each loop, n will increase by 1
    character := [SCRIPT THAT GETS CHARACTER ID]
    set new character(slice child(grid, n), character)
)
I changed my capitalization to match your code.

Again, I don't know how you intend to get each character. Where will the correct sequence of characters be stored? You have to answer that question to be able to make that work. In the meantime I wrote [SCRIPT THAT GETS CHARACTER ID] which you can replace with a new script that returns a character id.
My pronouns are they/them
Ps. I love my wife
User avatar
SwordPlay
Chemical Slime
Posts: 966
Joined: Sun Jan 22, 2017 9:32 am
Location: London, England
Contact:

Post by SwordPlay »

if you send the Japanese text sprites, me, or someone else, can try to make it for you.

This is how I would advise a simple approach.
You can add all kinds of complicated things, like whether text should be a colour, hira/kata, size, etc., with a code.
You probably need a start and end code like #5 to start colour 5, and #/ to restore default colour.
It's really up to you how to design it.
Maybe something like *K and *H to enter hira/kata modes. and */ to end it, perhaps?

Then you read a string, and interpret this segment by segment
You have to look at each character, and each collection of characters, and call the appropriate sprite.
It can be dissolved to change its size, or coloured with a palette. Not a big deal.
You also have to interpret the codes, probably by having a variable corresponding to each mode that changes when a code is read.
I don't know how you intend to enter text. In Romaji?

You would create new text sprites EVERY TIME you call it, and you would delete it when you are done with it.
After you call it, you can save it and load it in engine, for whatever reason.
Actually you don't have to delete the message. You could make it invisible or hide it somewhere, and restore it if you need it again.
Realistically it depends on what you want to use it for. Calling and freeing it as needed may be the easiest approach.
Last edited by SwordPlay on Thu Jan 28, 2021 1:48 am, edited 1 time in total.
"Imagination. Life is your creation."
bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

Thanks for your answers!

Post by bis_senchi »

Sword Play. Thank you for your remarks and for your offer to create a complex system
to implement japanese katakana and hiraganas.

As you know you can't use font table for drawing kanjis as the size of the font table space are
too small.

As you point out create a system in which you make appear the japanese character is also complex and difficult.

I choose a rather simple way. The two major problem you face with the OHRRPGCE for implementing japanese (or chinese or korean) are 1) the writting character size and 2) the character size numbers. The one you mentionned: beeing able to key in
directly in japanese/ chinses corean (may be the third one)

How did I solved them?
The text box sprite are 16*16 pixel. Their size are big enough to make the kanji recognizable when I draw them.

You can create 32768 which has each 16 individual titles.
To write dialogues in japanese you need 45 hiraganas+ 45 katakanas+ 2045 kanjis.
So If I use around 135 border tileset of each 16 invidual tiles to get all the writing
signs you need.

I've chosen box border sprite for both space and comfort
as you are not likely to draw tons of different borders for your dialogue boxes.
I could have used walthrought but they are only 8 individual tile large and you never know
exactly how many npcs you'll need for your whole game.

Getting a � when I type k and then an a like with the Microsoft IME is not that important.
The idea here is using tiles as writing blocks like Mister Guntenbger did when he printed his first bible with his printing press at the beginning of the Renaissance.

When I finished making all the fonts all that will be left is to make a table on open office document, in which I'll say for example that � is border sprite set n°4 and frame 2.

I may use another and/or the # and the comment function of the hss file
to have the sample of the sentence I want to write. I've made tests and
comments on the hss file can be made only witht he latin alphabet that means
using rômaji in japanese case.

All that will be left will giving the right numbers in the right order to have your sentence
display correctly.
It may be a bit difficult at the beginning but I'm confident you can get use to it.
With a paper and a pen to note the spelling mistakes while testing It should be ok.

#-----------------------------------------------------------
kylekrack

Thanks for the new script; changing the value of the sprite according to its place in the grid is exactly what I need!

I still have a question about part of the code you wrote. Set new character is
the script is the one you made. But what is the [SCRIPT THAT GETS CHARACTER ID] ??? How do I recognise this script?

As it is, when the script run I have an invlid script handle. The script debugger indicate
that the line for(n, 0, child count(grid)--1) do cannot be excuted properly

Code: Select all

#----------------------------------------------------
variable(n, character, grid)
grid := first grid child (menu handle) 
#first grid slice does not exist as a command  :hurr: It's first grid child

[img]for(n, 0, child count(grid)--1) do([/img]
    # in each loop, n will increase by 1
    character := [SCRIPT THAT GETS CHARACTER ID] #???
    set new character(slice child(grid, n), character)
)
Anyway that both of kylekrack and swordplay for you insights on implementation and
numerous pieces of advice.
Last edited by bis_senchi on Thu Jan 28, 2021 7:08 am, edited 3 times in total.
User avatar
kylekrack
Liquid Metal Slime
Posts: 1240
Joined: Mon Jun 16, 2014 8:58 am
Location: USA
Contact:

Post by kylekrack »

You have to write that script and then call it whatever you want. I don't know how you determine which character goes in each slot. I wrote [SCRIPT THAT GETS CHARACTER ID] like that so it was obvious that it's supposed to be replaced with something else.

I cannot help with making that script without more detail on how you know which character goes in each slot.
My pronouns are they/them
Ps. I love my wife
bis_senchi
Red Slime
Posts: 64
Joined: Sat Apr 20, 2019 8:59 am

Post by bis_senchi »

Thanks for your quick answer as always.
I'm think I got a glimpse of what you want to say.
The script set new character is for sprite alteration
and the other script SCRIPT THAT GETS CHARACTER ID
is for letter storing in global variable for later use

You said "how you know which character goes in each slot.?"
As I've explained in the last post it's the same order as one would use making a
newspaper using printer blocks or writing. It's from left
to the right and from up to down.

Let's take a example with the word test テスト

I've got the letter テ
-> box edge palette set 10, frame 2

I've got the letter ス
-> box edge palette set 10, frame 9

I've got the letter ト
-> box edge palette set 10, frame 10

Which character would got into which slot?
Let's say that it is the first word. The complete phrase would
be :

テスト�日�今日�ん��。
Today, there is a test

So in this example letter テ would go on the bottom left
and it's position in the child index would be "sliceChild(grid, 0)" ,
ス would go just after and it's position would be "sliceChild(grid, 1)"
and ト would be "sliceChild(grid, 2)"

I assume (based on what you said on your last post) that child count goes like this
in my case

0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,
15,16,17,18,19,20,21,22,23,24,25,26,27,28
29,30,31,32,33,34,35,36,37,38,38,40,41,42

So in my last screenshot sliceChild(grid, 2), sliceChild(grid, 3) and "sliceChild(grid, 4)"
had been put in grey.

Let's make another sentence :
先生�明日�テストを話������。
The teacher spoke about tomorrow's test

In this example letter テ would go on the bottom left
and it's position in the child index would be "sliceChild(grid, 6)" ,
ス would go just after and it's position would be "sliceChild(grid, 7)"
and ト would be "sliceChild(grid, 8)"

But the sprite references doesn't change

I've got the letter テ
-> still box edge palette set 10, frame 2

I've got the letter ス
-> still box edge palette set 10, frame 9

I've got the letter ト
-> still box edge palette set 10, frame 10

As you can see my characters ID is not linked to the grid which inside the dialogue box
but rather that to it's palette and frame reference.
Based on that what should I do?

Tell me if you still don't understand.Thanks a lot for the help as always
Last edited by bis_senchi on Fri Jan 29, 2021 5:15 am, edited 1 time in total.
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Hmmm... Since there is no easy way to store the Japanese text, and no easy way to type it, why use scripting for this at all?

Wouldn't it be simpler to just have hundreds of slice collections, one for each Japanese text box?
Post Reply