Post new topic    
Page «  1, 2, 3, 4, 5
Metal King Slime
Send private message
 
 PostTue Apr 06, 2021 12:22 pm
Send private message Reply with quote
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.

Quote:
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:
if (keyval(key:esc), xor, keyval(key:alt)) then, begin

This is a strange thing to write; I think you meant
Code:
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:
if (key is pressed(menu key)) then, begin
Red Slime
Send private message
Script test 11 
 PostWed Apr 07, 2021 8:50 am
Send private message Reply with quote
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:

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!
Liquid Metal King Slime
Send private message
 
 PostWed Apr 07, 2021 11:03 am
Send private message Reply with quote
Code:
    ) #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.
Red Slime
Send private message
hanks! but now... 
 PostThu Apr 08, 2021 5:33 am
Send private message Reply with quote
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. Smile The only problem left is cursor movement and detection.

Here is what the menu look like


Code:


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?
Metal King Slime
Send private message
 
 PostThu Apr 08, 2021 11:19 am
Send private message Reply with quote
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:

  # 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 (selection < lower limit) then (selection := upper limit) # wrap around from first to last
  if (selection > upper limit) then (selection := lower limit) # 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:
wait for key (key: space) # very important. allow fake text box to disappear naturally
if (key is pressed (key: space)) then, begin

You shouldn't need this check for Space at all, because there's a "wait for textbox" immediately before the break
Red Slime
Send private message
Problem with posting on the forum 
 PostFri Apr 09, 2021 12:21 pm
Send private message Reply with quote
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!



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



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
Quote:

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

Quote:

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.
#--------------------------------------------------------------------------------
Display posts from previous:
Page «  1, 2, 3, 4, 5