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

TMC
Metal King Slime
Posts: 4090
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Sorry, I haven't been following this thread at all. It's not fun to jump into a long confusing thread, and it's much harder to explain how to write and debug scripts like these than to write them!

trunkmenu isn't the script with the infinite loop, that's test11. Could you post test11?

One of the errors you posted, in trunkmenu, is on the line
sltest := slice child (menu items, selection)
The script debugger shows at the bottom "setvar(global72,slicechild(0,0)" which means that menuitems is global 72, and that menuitems is 0 and selection is 0. So the problem is that menuitems is 0. Looking up the script I see that menuitems isn't even set! Instead, it loads
menu items2 := lookup slice (sli: menu items, collection)
Fix that by replacing menuitems2 with menuitems. Why is menuitems a global variable? It should be a local in this script. If your global called menuitems is already used for something else then instead replace all instances of "menu items" with "menu items2" in this script.
If I remember correctly from what I learnt: you can't run a script which is itself inside a script...
except for a automnumber.
You can't run a subscript from another script or from an event in Custom.
"define script(autonumber, ...)" is obsolete, you can just remove any autonumber line like that.

Code: Select all

if (keyval(key:esc), xor, keyval(key:alt)) then, begin 
This is a strange thing to write; I think you meant

Code: Select all

if (key is pressed(key:esc) || key is pressed(key:alt)) then, begin 
which behaves almost identically. But you can write that even simpler as

Code: Select all

if (key is pressed(menu key)) then, begin
Last edited by TMC on Tue Apr 06, 2021 12:30 pm, edited 3 times in total.
bis_senchi
Red Slime
Posts: 60
Joined: Sat Apr 20, 2019 8:59 am

Script test 11

Post by bis_senchi »

Thnaks for all your remaks TMC! Here my script test11.

As it a "embettered version" for my trunk menu script so it look a bit similar to
the trunk menu script. Here it is

Code: Select all

define script (107, test 11, none)
#-----------------------------------------------------------------
script, test11, begin


suspend player
suspend npcs
show text box (33)#this for testing futur script menu
wait for text box


variable (menu items2, menu cursor, collection)
collection:= load slice collection (2)
# I assume it has the "menu items" lookup code
menu items2 := lookup slice (sli: menu items, collection)

# And the menu cursor slice too, lookup code "menu cursor"
cursor := lookup slice (sli: menu cursor, collection)

while (true) do (
  if (key press (use key)) then (
    # Activate selected item (fill this in
    switch (selection) do (
      case(0) do, begin	 #Monster 1 Blue Eyes
	  $10="this is the legendary blue eyes white dragon"
	  wait (3)
	  show text box (88)
	  wait for text box
	  clear string (10)
	  end #end for case 0
	  
	  case(1) do, begin #Monster 2 Mystical Elf
	  $10="this is the Mystical Elf"
	  wait (3)
	  show text box (88)
	  wait for text box
	  clear string (10)
	  end #end for case 1
	  
          case(2) do, begin #Monster 3 Hitosu Me Giant
	  $10="this is Histosu me Giant"
	  wait (3)
	  show text box (88)
	  wait for text box
	  clear string (10)
	  end #end for case 2
	  
	  case(3) do, begin #Monster 3 Baby Dragon
	  $10="this is Baby Dragon"
	  wait (3)
	  show text box (88)
	  wait for text box
	  clear string (10)
	  end #end for case 3
	  
	  case(4) do, begin #Monster 4 Ryu Kishin
	  $10="this is Ryu Kishin"
	  wait (3)
	  show text box (88)
	  wait for text box
	  clear string (10)
	  end #end for case 4
	  
	  case(5) do, begin #Monster 5 Feral Imp
	  $10="this is Ryu Kishin"
	  wait (3)
	  show text box (88)
	  wait for text box
	  clear string (10)
	  end #end for case 5
	  
	  case(6) do, begin #Monster 6 Winged dragon
	  $10="this is Winged dragon, guardian of the forteress"
	  wait (3)
	  show text box (88)
	  wait for text box
	  clear string (10)
	  end #end for case 6
	  
	  
    ) #end for switch
    break  # exit
  )#end for the if
  end #end for the while


wait for key (key: space) # very important. allow fake text box to disappear naturally
if (key is pressed (key: space)) then, begin
free slice (collection)
wait (3)

end #end for the if


resume player
resume npcs 


With the version of the code above, I've got the message " A script may be stuck in
an infinite loop. Press F1 for help." I've given the script to a npc (it is launched when I speak
to the npc) and no other script or menu is launched.

Some other message may appear after, but for the moment but beeing stuck in a "while loop"
seems to be main problem right wow!

Anyway, as always thanks in advance for your remarks and piece of advice!
Last edited by bis_senchi on Wed Apr 07, 2021 8:55 am, edited 1 time in total.
User avatar
Bob the Hamster
Liquid Metal King Slime
Posts: 7449
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

Code: Select all

    ) #end for switch
    break  # exit
  )#end for the if
  wait(1)
  end #end for the while
You need a "wait(1)" that is inside the while but outside the if.

That is what causes the infinite loop.
bis_senchi
Red Slime
Posts: 60
Joined: Sat Apr 20, 2019 8:59 am

hanks! but now...

Post by bis_senchi »

Thanks a lot James!. The while loop was suck indeed because of a missing wait (1)


So now the script has no errors and launch correcty. :) The only problem left is cursor movement and detection.

Here is what the menu look like
Image

Code: Select all


wait for key (key: any key) # expect the player to press a key

if (key is pressed (key: up)) then, begin
???
end

if (key is pressed (key: down)) then, begin
???? 
end

if (key is pressed (key: right)) then, begin
???
end

if (key is pressed (key: left)) then, begin
???
end 

if (key is pressed (key: space)) then, begin #leave
free slice (collection)
wait (3) 

How should I modifiy my script?
Last edited by bis_senchi on Thu Apr 08, 2021 5:34 am, edited 1 time in total.
TMC
Metal King Slime
Posts: 4090
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

You're using Space to leave the menu? That's quite odd. Make sure your "if(key is pressed(key: space))" appears before "if(keypress(use key))".

Odd, I thought there was a version of the script earlier in this thread with the up/down keys, but I don't see it.

The trunkmenu script is nearly complete, except for handling upkey and downkey. You can handle those by replace the "Change the selection" section of the trunkmenu script with this:

Code: Select all

  # Change the selection
  variable(upper limit, lower limit)
  lower limit:=0
  upper limit:=5

  if (keypress (up key)) then (selection -= 1)
  if (keypress (down key)) then (selection += 1)

  if &#40;selection < lower limit&#41; then &#40;selection &#58;= upper limit&#41; # wrap around from first to last
  if &#40;selection > upper limit&#41; then &#40;selection &#58;= lower limit&#41; # wrap around from last to first
Don't add "wait for key(any key)". It's not necessary if using "keypress" instead of "key is pressed".

What do you want left/right to do? Same as up/down?
Of course, usekey is already handled in trunkmenu.

As for the monster selection menu, just copy in the same code from trunkmenu for moving the cursor into that script. The difference is that instead of a slice with the "menu items" lookup code I see it has the "scroll container" lookup code.

BTW, in test11:

Code: Select all

wait for key &#40;key&#58; space&#41; # very important. allow fake text box to disappear naturally
if &#40;key is pressed &#40;key&#58; space&#41;&#41; then, begin 
You shouldn't need this check for Space at all, because there's a "wait for textbox" immediately before the break
Last edited by TMC on Thu Apr 08, 2021 11:23 am, edited 1 time in total.
bis_senchi
Red Slime
Posts: 60
Joined: Sat Apr 20, 2019 8:59 am

Problem with posting on the forum

Post by bis_senchi »

Sorry There seems to have problems when I save my message. I'll edit this one when
this problem will be solve.

#----------------------------------------------------------------------------------------
So here is what I wanted to say. As always thanks TMC
So I worked on my slice collection and I've added a sub menu along with a place where to quit!

Image

It's a bit different from the gameplay in the original game but game engine and game limitation
are different, so I need to make some adjustement

Image

As you can see in the original game the previous screen is blured to focus on current selection.
Do you know if we can do that by using look up slice manipulation ?

TMC asked
What do you want left/right to do? Same as up/down?
Well what I want for the arrow keys up/down/right/left is to do what you made them do
indicate current selection on the menu and also in the sub menu I've added above when it is opened.

I also need to add line which change text color to really put emphasis on selection whith slice child ans set text color.

Where should I put them?

You also asked about keys
You're using Space to leave the menu? That's quite odd. Make sure your "if(key is pressed(key: space))" appears before "if(keypress(use key))".
As it is now I'll use the key space place on "quit" to lave the menu. May be later I'll come back to the code and change by a indication press esc to leave.
Gameplay is not fix on that particular point.

As always thanks in advance for your answer.
#--------------------------------------------------------------------------------
Last edited by bis_senchi on Sat Apr 10, 2021 3:44 am, edited 7 times in total.
TMC
Metal King Slime
Posts: 4090
Joined: Sun Apr 10, 2011 9:19 am

Re: Problem with posting on the forum

Post by TMC »

bis_senchi wrote:As you can see in the original game the previous screen is blured to focus on current selection.
Do you know if we can do that by using look up slice manipulation ?
Yes, this (darkening the background, not blurring it) is easy. In the slice collection for the bottom (trrunk?) menu create a black rect slice which covers the screen, above the menu, then set it to "Translucency: Blend" and Opacity about 50%. This will darken everything behind it. Then give it a lookup code (e.g. "darken rect") and set it to "Visible: No".
Then use

Code: Select all

set slice visible &#40;lookup slice&#40;sli&#58; darken rect&#41;, true&#41;
to turn it on.

I also need to add line which change text color to really put emphasis on selection whith slice child ans set text color.

Where should I put them?
The version of the trunkmenu script you posted here already does this. It has two lines "set text color (sltest, 15) # Change this to normal text colour!" and "set text color (sltest, 7) # Change this to highlighted text colour!". Just copy from that script into your other menu scripts.

BTW if you are using nightly builds you can now instead write

Code: Select all

set text color &#40;sltest, ui&#58;Text&#41;  # Normal text UI colour

Code: Select all

set text color &#40;sltest, ui&#58;SelectedItem&#41; # Highlighted text UI colour
If you use ui:SelectedItem then the colour will flash between the two selection colours automatically!
Last edited by TMC on Sun Apr 11, 2021 4:50 am, edited 2 times in total.
bis_senchi
Red Slime
Posts: 60
Joined: Sat Apr 20, 2019 8:59 am

Post by bis_senchi »

As always thanks for your help:

Script debugger said that slice child is invalid slice handle and that set text color is also a
invalid.

Code: Select all


#------------------------------------------------------------------------------------------------------------------
script, test 11, begin

suspend player
suspend npcs
show text box &#40;33&#41;
wait for text box


variable &#40;menu items2, menu cursor, collection, sltest2&#41;
collection&#58;= load slice collection &#40;2&#41;
# I assume it has the "menu items" lookup code
menu items2 &#58;= lookup slice &#40;sli&#58; menu items, collection&#41;

# And the menu cursor slice too, lookup code "menu cursor"
cursor &#58;= lookup slice &#40;sli&#58; menu cursor, collection&#41;

while &#40;true&#41; do &#40;
  if &#40;key press &#40;use key&#41;&#41; then &#40;
    # Activate selected item &#40;fill this in
    switch &#40;selection&#41; do &#40;
      case&#40;0&#41; do, begin	 #Monster 1 Blue Eyes
	  $10="this is the legendary blue eyes white dragon"
	  wait &#40;3&#41;
	  show text box &#40;88&#41;
	  wait for text box
	  clear string &#40;10&#41;
	  end #end for case 0
	  
	  case&#40;1&#41; do, begin #Monster 2 Mystical Elf
	  $10="this is the Mystical Elf"
	  wait &#40;3&#41;
	  show text box &#40;88&#41;
	  wait for text box
	  clear string &#40;10&#41;
	  end #end for case 1
	  
      case&#40;2&#41; do, begin #Monster 3 Hitosu Me Giant
	  $10="this is Histosu me Giant"
	  wait &#40;3&#41;
	  show text box &#40;88&#41;
	  wait for text box
	  clear string &#40;10&#41;
	  end #end for case 2
	  
	  case&#40;3&#41; do, begin #Monster 3 Baby Dragon
	  $10="this is Baby Dragon"
	  wait &#40;3&#41;
	  show text box &#40;88&#41;
	  wait for text box
	  clear string &#40;10&#41;
	  end #end for case 3
	  
	  case&#40;4&#41; do, begin #Monster 4 Ryu Kishin
	  $10="this is Ryu Kishin"
	  wait &#40;3&#41;
	  show text box &#40;88&#41;
	  wait for text box
	  clear string &#40;10&#41;
	  end #end for case 4
	  
	  case&#40;5&#41; do, begin #Monster 5 Feral Imp
	  $10="this is Ryu Kishin"
	  wait &#40;3&#41;
	  show text box &#40;88&#41;
	  wait for text box
	  clear string &#40;10&#41;
	  end #end for case 5
	  
	  case&#40;6&#41; do, begin #Monster 6 Winged dragon
	  $10="this is Winged dragon, guardian of the forteress"
	  wait &#40;3&#41;
	  show text box &#40;88&#41;
	  wait for text box
	  clear string &#40;10&#41;
	  end #end for case 6
	  
	  
    &#41; #end for switch
    break  # exit
  &#41;#end for the if
  wait &#40;1&#41; #very important prevent while loop  
  end #end for the while


wait for key &#40;any key&#41; # very important. allow fake text box to disappear naturally
if &#40;key is pressed &#40;key&#58; space&#41;&#41; then, begin
free slice &#40;collection&#41;
wait &#40;3&#41;
end #end for the if
  
  # First change the currently selected slice to deselected appearence
  # &#40;for simplicity, do this even if the selection doesn't change&#41;
  sltest2 &#58;= slice child &#40;menu items2, selection&#41;  # This is the slice for the &#40;previous&#41; selected item, which I assume is a text slice
  set text color &#40;sltest2, 15&#41;  # Change this to normal text colour!


  # Change the selection
  variable&#40;upper limit, lower limit&#41;
  lower limit&#58;=0
  upper limit&#58;=5

  if &#40;keypress &#40;up key&#41;&#41; then &#40;selection -= 1&#41;
  if &#40;keypress &#40;down key&#41;&#41; then &#40;selection += 1&#41;

  if &#40;selection < lower limit&#41; then &#40;selection &#58;= upper limit&#41; # wrap around from first to last
  if &#40;selection > upper limit&#41; then &#40;selection &#58;= lower limit&#41; # wrap around from last to first

  

resume player
resume npcs 
 
end #end of the script
As it is, nothing still happens when I press arrows. The text is also not selected.
Anyways, It's already a good thing that by using slice look up I can get the same effet when
the sub menu is opened.

Now that I think about it "selection" is not defined as a local variable but global... that may be where the problem comes from.

Anyways. As always thanks for your help and advice.
Last edited by bis_senchi on Sun Apr 11, 2021 2:10 pm, edited 3 times in total.
TMC
Metal King Slime
Posts: 4090
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

You need to put the code for moving the selection cursor inside the while loop!

Also, you forgot to add the line "set text color (sltest2, 7)".

Yes, 'selection' should be a local variable.

I made these fixes and also another bug and cleaned up the script for you:

Code: Select all

# This script is called after putting the monster name in string 10
script, show monster, begin
  show text box &#40;88&#41;
  wait for text box
  clear string &#40;10&#41;
end


script, test 11, begin

  suspend player
  suspend npcs
  show text box &#40;33&#41;
  wait for text box

  variable &#40;menu items2, cursor, collection, selection, selected slice&#41;
  collection &#58;= load slice collection &#40;2&#41;
  menu items2 &#58;= lookup slice &#40;sli&#58; menu items, collection&#41;
  cursor &#58;= lookup slice &#40;sli&#58; menu cursor, collection&#41;

  while &#40;true&#41; do &#40;

    if &#40;key press &#40;cancel key&#41;&#41; then &#40;break&#41;  # Exit the menu

    if &#40;key press &#40;use key&#41;&#41; then &#40;
      # Activate selected item
      switch &#40;selection&#41; do &#40;
        case&#40;0&#41;    #Monster 1 Blue Eyes
          $10="this is the legendary blue eyes white dragon"
          show monster
        case&#40;1&#41; #Monster 2 Mystical Elf
          $10="this is the Mystical Elf"
          show monster
        case&#40;2&#41; #Monster 3 Hitosu Me Giant
          $10="this is Histosu me Giant"
          show monster
        case&#40;3&#41; #Monster 3 Baby Dragon
          $10="this is Baby Dragon"
          show monster
        case&#40;4&#41; #Monster 4 Ryu Kishin
          $10="this is Ryu Kishin"
          show monster
        case&#40;5&#41; #Monster 5 Feral Imp
          $10="this is Ryu Kishin"
          show monster
        case&#40;6&#41; #Monster 6 Winged dragon
          $10="this is Winged dragon, guardian of the fortress"
          show monster
      &#41;
      break  # exit menu
    &#41; #end of 'if use key'


    # First change the currently selected slice to deselected appearence
    # &#40;for simplicity, do this even if the selection doesn't change&#41;
    if &#40;selected slice&#41; then &#40;
      set text color &#40;selected slice, 7&#41;  # Change this to normal text colour! &#40;eg ui&#58;Text&#41;
    &#41;

    # Change the selection
    if &#40;keypress &#40;up key&#41;&#41; then &#40;selection -= 1&#41;
    if &#40;keypress &#40;down key&#41;&#41; then &#40;selection += 1&#41;

    variable&#40;upper limit, lower limit&#41;
    lower limit &#58;= 0
    upper limit &#58;= child count &#40;menu items2&#41; -- 1
    if &#40;selection < lower limit&#41; then &#40;selection &#58;= upper limit&#41; # wrap around from first to last
    if &#40;selection > upper limit&#41; then &#40;selection &#58;= lower limit&#41; # wrap around from last to first

    selected slice &#58;= slice child &#40;menu items2, selection&#41;  # Slice for the selected item
    # Change the selected slice to selected appearence
    set text color &#40;selected slice, 15&#41;  # Change this to highlighed text colour!  &#40;eg ui&#58;SelectedItem&#41;

    wait &#40;1&#41;
  end #end for the while

  wait &#40;3&#41;
  free slice &#40;collection&#41;
  resume player
  resume npcs

end
Note: the "cursor" slice isn't used.
Last edited by TMC on Mon Apr 12, 2021 3:26 am, edited 1 time in total.
bis_senchi
Red Slime
Posts: 60
Joined: Sat Apr 20, 2019 8:59 am

Advice about look up codes

Post by bis_senchi »

So I've tested the script and the problems are still there.

When I press the down arrow selection doesn't change: the cursor doesn't move, the text color also doesn't change and when I press the arrow the text box indicate that it is always the first monster of the list which has been selected...

It's as if there are no error messages the command set text color (and may be also key press)
wouldn't function properly.
I've made a test with show value and place it after set text color and it appeared on screen which means that the script reads correctly at leat until that point....
After some search the problem is simply that my rectangle in my slice tree doesn't have a look up code Sorry :hurr: .

Just like with the previous menu, I should use the look up "items menu" isn't it?

As always thanks for your help!
TMC
Metal King Slime
Posts: 4090
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

Oh, yes, I warned that the script didn't do anything with the cursor.
Just add the following line above the wait(1). I copied this line from the version of the script posted earlier in this thread. Once you had a working menu script you should have just made a copy of it for the second menu, instead of writing a new one.

Code: Select all

    # Move the cursor
    put slice &#40;cursor, slice x &#40;selected slice&#41; -- -15, slice y &#40;selected slice&#41; -- 1&#41; 
I see SwordPlay wrote a post about how to position the cursor, on the previous page of this thread.

If you look at the script you'll see it assumes that the parent slice of all the menu items has the menu items lookup code and the cursor slice has the cursor lookup code.
bis_senchi
Red Slime
Posts: 60
Joined: Sat Apr 20, 2019 8:59 am

I've added the and still nothing happens

Post by bis_senchi »

I've added the lines and still nothing happens. When I press the space bar I leave the menu but when I press the arrows, nothing.

The text which is the monster's name is not selected either....
That has to do with look up code in my slice tree. Where should I place
menu items?

Is there another slice up code which I should check?

As always thanks for in advance for your help!
TMC
Metal King Slime
Posts: 4090
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

I tested out the script myself and found that there was a problem because I made the "menu items" slice a grid slice. To fix that, I had to change the line to move the cursor to

Code: Select all

    # Move the cursor
    put slice screen &#40;cursor, slice screen x &#40;selected slice&#41; -- 15, slice screen y &#40;selected slice&#41; -- 1&#41; 
Then the position of the cursor in the slice collection doesn't matter.

The slice with the "menu items" lookup can be anywhere in the tree as long as its children are (only) the menu item slices. The cursor must not be a child of it.
Attachments
test0041.png
test0041.png (4.18 KiB) Viewed 274 times
Last edited by TMC on Sat Apr 17, 2021 10:51 am, edited 1 time in total.
bis_senchi
Red Slime
Posts: 60
Joined: Sat Apr 20, 2019 8:59 am

String update

Post by bis_senchi »

Thanks for all your remarks as always TMC. Here is the script as it is:

Code: Select all


script, test 11, begin

suspend player
suspend npcs

  show text box &#40;33&#41;
  wait for text box

  variable &#40;menu items, cursor, collection, selection, selected slice&#41;
  collection &#58;= load slice collection &#40;2&#41;
  menu items &#58;= lookup slice &#40;sli&#58; menu items, collection&#41;
  cursor &#58;= lookup slice &#40;sli&#58; menu cursor, collection&#41;
  selected slice &#58;= slice child &#40;sli&#58; menu items, selection&#41;

  while &#40;true&#41; do &#40;

    if &#40;key press &#40;cancel key&#41;&#41; then &#40;break&#41;  # Exit the menu

    if &#40;key press &#40;use key&#41;&#41; then &#40;
      # Activate selected item
      switch &#40;selection&#41; do &#40;
        case&#40;0&#41;    #Monster 1 Blue Eyes
          $10="this is the legendary blue eyes white dragon"
          wait &#40;3&#41;
	      show text box &#40;88&#41;
	      wait for text box
	      clear string &#40;10&#41;
        case&#40;1&#41; #Monster 2 Mystical Elf
          $10="this is the Mystical Elf"
          wait &#40;3&#41;
	      show text box &#40;88&#41;
	      wait for text box
	      clear string &#40;10&#41;
        case&#40;2&#41; #Monster 3 Hitosu Me Giant
          $10="this is Histosu me Giant"
          wait &#40;3&#41;
	      show text box &#40;88&#41;
	      wait for text box
	      clear string &#40;10&#41;
        case&#40;3&#41; #Monster 3 Baby Dragon
          $10="this is Baby Dragon"
          wait &#40;3&#41;
	      show text box &#40;88&#41;
	      wait for text box
	      clear string &#40;10&#41;
        case&#40;4&#41; #Monster 4 Ryu Kishin
          $10="this is Ryu Kishin"
          wait &#40;3&#41;
	      show text box &#40;88&#41;
	      wait for text box
	      clear string &#40;10&#41;
        case&#40;5&#41; #Monster 5 Feral Imp
          $10="this is Ryu Kishin"
          wait &#40;3&#41;
	      show text box &#40;88&#41;
	      wait for text box
	      clear string &#40;10&#41;
        case&#40;6&#41; #Monster 6 Winged dragon
          $10="this is Winged dragon, guardian of the fortress"
          wait &#40;3&#41;
	      show text box &#40;88&#41;
	      wait for text box
	      clear string &#40;10&#41;
      &#41;
      break  # exit menu
    &#41; #end of 'if use key'


    # First change the currently selected slice to deselected appearence
    # &#40;for simplicity, do this even if the selection doesn't change&#41;
    if &#40;selected slice&#41; then &#40;
    set text color &#40;selected slice, 7&#41;  # Change this to normal text colour! &#40;eg ui&#58;Text&#41;
    &#41;

    # Change the selection
    if &#40;keypress &#40;up key&#41;&#41; then &#40;selection -= 1&#41;
    if &#40;keypress &#40;down key&#41;&#41; then &#40;selection += 1&#41;

    variable&#40;upper limit, lower limit&#41;
    lower limit &#58;= 0
    upper limit &#58;= child count &#40;menu items&#41; -- 1
    if &#40;selection < lower limit&#41; then &#40;selection &#58;= upper limit&#41; # wrap around from first to last
    if &#40;selection > upper limit&#41; then &#40;selection &#58;= lower limit&#41; # wrap around from last to first

    selected slice &#58;= slice child &#40;menu items, selection&#41;  # Slice for the selected item
    # Change the selected slice to selected appearence
    put slice screen &#40;cursor, slice screen x &#40;selected slice&#41; -- 15, slice screen y &#40;selected slice&#41; -- 1&#41; 
	set text color &#40;selected slice, 15&#41;  # Change this to highlighed text colour!  &#40;eg ui&#58;SelectedItem&#41;
    wait &#40;1&#41;
  end #end for the while

  wait &#40;3&#41;
  free slice &#40;collection&#41;
  resume player
  resume npcs
 
end #end of the script
I didn't create a script show monster like in your version of the script, because this line will be change when I want to include the sub menu. When a a player access a card in the trunk menu he/she can 1- send it to the deck 2-see the details (get all infos about the monster & card use) 3- return to the previous menu (see my post of April 9th to see what I'm talking about)

Image

Image

Image

As you can see there is still an error message... and when I move the cursor the grey selection does not back to white... I need to think of a way to "record" the previous position so that the
set text color works efficiently...

I didn't (yet) use a grid. Could you please explain why using a grid would help to put the cursor in screen correctly? Anyway feel free to reply with all king of pieces of advice.

Thank you again woth Swordplay & TMC for keeping answering my numerous questions.
Last edited by bis_senchi on Wed Apr 21, 2021 4:14 am, edited 1 time in total.
TMC
Metal King Slime
Posts: 4090
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

You added the line "selected slice := slice child (sli: menu items, selection)" near the top of the script. It's throwing the error message. That's incorrect, the first argument to "slice child" is a slice handle, not a sli:... lookup code. Delete it; it's not needed (because I wrote "if (selected slice)" later in the script).

To get the text colour to change to the desired colours you need to change the two lines

Code: Select all

    set text color &#40;selected slice, 7&#41;  # Change this to normal text colour! &#40;eg ui&#58;Text&#41; 

Code: Select all

    set text color &#40;selected slice, 15&#41;  # Change this to highlighed text colour!  &#40;eg ui&#58;SelectedItem&#41; 
In the default palette colour 7 is grey and 15 is white, so you probably want the first line to use colour 15 and the second to be something else.

A grid slice isn't needed, it's only useful for evenly spacing a lot of slices. But in this case one of your menu items is two lines high, so you can't use a grid slice anyway.
Post Reply