Castle Paradox Forum Index Castle Paradox

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
 Gamelist   Review List   Song List   All Journals   Site Stats   Search Gamelist   IRC Chat Room

help to clean and embetter mykeypress script

 
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP!
View previous topic :: View next topic  
Author Message
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Wed Jan 13, 2010 2:43 am    Post subject: help to clean and embetter mykeypress script Reply with quote

I'm working on my keypress script

I working on reimplementing the esc and space bar behaviour.

Just like with the basic main menu, I would like the player to access the new menu pressing the space bar and to go back to the previous menu just pressing esc.

Originally I intended to use the switch command and a global variable but soon after I installed Ypsiliform a error message appeared

game.exe wrote:

script error !
close menu invalid menu handle -1
call chain (current script last)

onkeypressript ->leave game menu

ignore
don't display anymore scripts errors
set error suppression level to 4
supress errors from this source
exit game (without saving )
enter debugger



Code:


#My on-keypress script outside battle

plotscript, on keypress script, begin 

if (key is pressed(key: numlock)) then, begin # key is numlock: Pause
while(key is pressed(key: numlock)) do, begin
if (pauseisactive==false) then, begin
pause script
end, else, begin
#thus, pauseisactive must be true
unpaused script
end #end of the first if
end  #end for the while
end #end of the second if


if (key is pressed(key:esc), xor, key is pressed(key:alt)) then, begin
while(key is pressed(key:esc), xor, key is pressed(key:alt)) do, begin
switch (escape behaviour) do, begin   

case (0) do, begin
if (see main menu ==false) then, begin
game menu
end, else, begin
leave game menu
end #end for the (see main menu)
end #end for the case

case (1) do, begin #leave status menu

fade screen out (0,0,0)

variable (handle)
handle:=open menu (6)#main menu pops up

hide string (1) #hide menu name
string from textbox (8, 53, 0) #text box 53 L0 -> chance
string from text box (11,53, 1) #text box 53 L1 -> money
show string at (8, 147, 18)
show string at (11, 147, 31)

fade screen in
escape behaviour:=0
wait (1)
end #end for the case

case (2) do, begin #leave items menu

fade screen out (0,0,0)
#variable (handle) #already defined : no need to add it variable needed to close the menu
handle:= find menu ID (2)
close menu (handle)
wait (2)
handle:= find menu ID (8)
close menu (handle)
open menu (6)#main menu pops up

hide string (1) #hide menu name
string from textbox (8, 53, 0) #text box 53 L0 -> chance
string from text box (11,53, 1) #text box 53 L1 -> money
show string at (8, 147, 18)
show string at (11, 147, 31)
fade screen in

escape behaviour:=0
wait (1)
end #end for the case


case (3) do, begin #leave use item menu

handle:= find menu ID (8) #use item menu
close menu (handle)
wait (2)
open menu (6)#main menu pops up


escape behaviour:=0
wait (1)
end #end for the case

end #end for the switch
end #end for the while
end #end for if key is pressed


end #end of the plotscript here
#------------------------------------------------------------------------------
plotscript, leave game menu, begin

suspend player

show backdrop (0) #show absolutely nothing
fade screen out 
set hero picture (me, MyPicSet)

if (hero by slot (1) <> -1) then, begin #  if slot (1) is occupied
set hero picture (1, heropic1)
end
if (hero by slot (2) <> -1) then, begin #  if slot (2) is occupied
set hero picture (2, heropic2)
end
if (hero by slot (3) <>- 1) then, begin #  if slot (3) is occupied
set hero picture (3, heropic3)
end
camera follows hero (me)

game menu active:= false #make sure player keeps suspended
wait (1)

hide string (8)
hide string (11)

teleport to map (YourM, YourX, YourY)   
close menu (top menu) #permet de fermer le menu
escape behaviour:=0  #permet de donner le bon cas pour esc
wait (1)
fade screen in
show map

see main menu:=false
wait (1) #Wait 1 is very important. Do not delete the command
resume player

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

#------------------------------------------------------------------------------
# item menu
plotscript, item menu, begin

fade screen out (0,0,0)

hide string (11) # hide luck and yens infos not in status menu
hide string (8)
close menu (top menu) # close previous menu : main menu 6

$0="Items"

string from textbox (1, 53, 2) #text box 53 L2 is for menu names
show string at (1, 17, 21) # Sub menu name location

escape behaviour:=2 #gives correct behaviour for escape key so that the player can leave without any pbs
wait(1) #very very important


open menu (2) #open item menu
wait (2)  #make sure menu already poped up when screen goes back to normal
open menu (8) #menu use item activé par défaut
wait (4)
variable (handle)
handle:= find menu ID (2) # menu 2 desactivé
set menu bit (handle, menubit:no controls, off)

fade screen in

end #end for the plotscript
#-----------------------------------------------------------------------------
#player has chosen to give a nikuman to one of the hero...
plotscript, use nikuman, begin


variable (hero0, hero1) # check who is here or not and give npc correct stuff
hero 0:= hero by slot (0)
hero 1:= hero by slot (1)

variable (hero 2, hero3)
hero 2:= hero by slot (2)
hero 3:= hero by slot (3)

escape behaviour:=3 #(gives correct behaviour for the esc key)
wait (1)

variable (handle)
handle:= find menu ID (2) #item menu
set menu bit (handle, menubit:no controls, off)
close menu (handle)
handle:= find menu ID (8) #use item menu
close menu (handle)
wait (3)

$0="Use Item" #change name to nikuman
hide string (1) #hide + show update menu name
wait (3)
string from textbox (1, 53, 2) #text box 53 L2 is for menu names
show string at (1, 17, 21) # Sub menu name location

suspend box advance
show text box (61) #chosen item description + item name


if (hero 0 ==hero:sanzo sama) then, begin # if Sanzo is in slot 0 then open the right menu at the right place
set npc direction (4, west) #npc 3 is Sanzo
# no need to change graphics -> npc already have the correct appearance

open menu (11) #hero slot sanzo menu
handle:= find menu ID (11)
set menu offset x(handle, 5) #coordonnées à revoir
set menu offset y(handle, 8)

end, else, begin
if (hero 0 ==hero:Sha Gojyo) then, begin
set npc direction  (4, west)  #npc 4 became Sha Gojyo
Alter NPC (4,NPCstat:picture,4) 
Alter NPC (4,NPCstat:palette,3)

open menu (14) #hero slot gojyo menu
handle:= find menu ID (14)
set menu offset x(handle, 5)
set menu offset y(handle, 55)

wait (1)

end, else, begin
if (hero 0 ==hero:Hakkai) then, begin
set npc direction (4, west) #npc 4 became Hakkai
Alter NPC (4,NPCstat:picture,5) 
Alter NPC (4,NPCstat:palette,4)

open menu (13) #hero slot gojyo menu
handle:= find menu ID (13)
set menu offset x(handle, 5)
set menu offset y(handle, 55)

end, else, begin
if (hero 0 ==hero:Goku) then, begin
set npc direction (4, west) #npc 4 became Son Goku
Alter NPC (4,NPCstat:picture,7) 
Alter NPC (4,NPCstat:palette,7)

open menu (12) #hero slot gojyo menu
handle:= find menu ID (12)
set menu offset x(handle, 5)
set menu offset y(handle, 55)

end
end
end

if (hero 1 ==hero:sanzo sama) then, begin # if Sanzo is in slot 1 then open the right menu at the right place
set npc direction (2, west) #npc 2 became Sanzo
Alter NPC (2,NPCstat:picture,6) 
Alter NPC (2,NPCstat:palette,6)

open menu (11) #hero slot gojyo menu
handle:= find menu ID (11)
set menu offset x(handle, 45)
set menu offset y(handle, 15)

end, else, begin

if (hero 1 ==hero:Sha Gojyo) then, begin
set npc direction (2, west) #npc 2 became Gojyo
Alter NPC (2,NPCstat:picture,4) 
Alter NPC (2,NPCstat:palette,3)

open menu (14) #hero slot gojyo menu
handle:= find menu ID (14)
set menu offset x(handle, 45)
set menu offset y(handle, 15)

end, else, begin
if (hero 1 ==hero:Hakkai) then, begin
set npc direction (2, west) #npc 2 became Hakkai
# no alter NPC already have the correct appearance

open menu (13) #hero slot menu Hakkai
handle:= find menu ID (13)
set menu offset x(handle, 45)
set menu offset y(handle, 15)

if (hero 1 ==hero:Goku) then, begin
set npc direction (2, west) #npc 2 became Son Goku
Alter NPC (2,NPCstat:picture,7) 
Alter NPC (2,NPCstat:palette,7)

open menu (13) #hero slot menu Goku
handle:= find menu ID (13)
set menu offset x(handle, 45)
set menu offset y(handle, 15)

end, else, begin
Alter NPC (2 ,NPCstat:picture,0)  # No Hero 1
Alter NPC (2 ,NPCstat:palette,0)

end
end
end
end
end

end #end of the plotscript
#-----------------------------------------------------------------------------


To help you to understand here's a little summary

The new main menu is menu 6. It has 6 items

Items
Accessories
Formation
Status
Techniques
Puzzle
Save
Quit

By now, I'm working on the first one, the item menu. When the player press the space bar the script "item menu" is launched. (and some other stuff to adapt the menu map)

The item menu (menu 2) is composed of 3 items

Use items
Sort items
Rare items

And that's when things gets a bit complicated. When the player goes into the item menu, the use items script is activated (but only when the player first arrive) by default and the use items menu runs.

The use menu runs and have several items

Nikuman
Shoronpo
M.Stone
(Other to come )

That makes 1 (items script) 2(use items) 3 (use nikuman) scripts that may run one after another If the player does not choose esc.

I also still have to add code lines an a 4th sub-script which implies to implement some menu switching because we still don't know who sill use the items!

Any help and advise to keep the code clean is welcome!

As it may not be easy to understand when you're not the one coding : feel free t ask any question about something that would not be clear!
_________________
It's time to make games!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Wed Jan 13, 2010 8:39 am    Post subject: Reply with quote

Quote:
script error !
close menu invalid menu handle -1
call chain (current script last)

onkeypressript ->leave game menu

ignore
don't display anymore scripts errors
set error suppression level to 4
supress errors from this source
exit game (without saving )
enter debugger


This error message tells you that you called close menu with an invalid menu handle, -1. This occured in the script leave game menu (which was called from onkeypressscript). 'close menu' appears just once in this script:
Code:
close menu (top menu) #permet de fermer le menu

Now, topmenu returns -1 when there are no menus open. That is the problem.

I notice that there does not appear to be a proper check preventing the onkeypressscript from running twice at once. You can check this very simply: when the error occurs, select "Enter debugger". You will then see a list of all the scripts currently running. You might see "onkeypressscript" twice.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Thu Jan 14, 2010 1:36 am    Post subject: Not using "top menu" make things a bit better! Reply with quote

I've replaced the top menu but classic close menu lines and it's a bit better.

What commands should I use to I check that my onkeypresscript does not run twice at once?

If the player presses esc how do I activate the good script without launching again onkeypress? Could a while loop solve the problem? May be not.

I'm using one with esc basic behaviour when the player presses esc a second time soon after launching my main menu : I use a global variable called see main menu in code and game.exe keeps on complaining that
you don't leave the menu properly....

Any idea is welcome. Thanks once more for the precious advice!
_________________
It's time to make games!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Fri Jan 15, 2010 9:08 am    Post subject: Reply with quote

Here's an article about only triggering on-keypress scripts once:
'Why does my on-keypress script freeze/produce errors when I hold down a key?'

But I don't understand what you mean by "classic close menu lines" or most of the rest of your post.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Sat Jan 16, 2010 12:55 am    Post subject: I think I managed to prevent some bug but... Reply with quote

I think I managed to prevent the keypress script from running several times in the backgound but... game.exe still complains about an error.

Here's what the debugger says (click on the picture to make it bigger and read what game.exe' debugger complains about)



Could someone explain me what the debugger says? There seems to have some news about what line in the code (in what script) creates problem. How do I know which one?

As always thanks in advance for the help!
_________________
It's time to make games!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Fri Jan 22, 2010 8:42 am    Post subject: Reply with quote

Unfortunately the script debugger is hard to understand. However as you can see, it says "close menu (0)". 0 is never a valid menu handle. This is actually exactly the same error that you reported before, however due to an engine bug, whenever you try and use any invalid menu or menu item handle, the Error message box will say "invalid menu handle -1". The script debugger tells you that the actual value is 0, which is what topmenu returns when there is no menu open.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Sun Jan 24, 2010 11:08 pm    Post subject: so this is a bug... Reply with quote

Well this is a good thing to know! The problem does not come from my code but from a bug of game.exe.

Has it been reported yet? If yes what's its number?
_________________
It's time to make games!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
TMC
On the Verge of Insanity




Joined: 05 Apr 2003
Posts: 3240
Location: Matakana

PostPosted: Mon Jan 25, 2010 5:46 pm    Post subject: Reply with quote

No, you misunderstand. The engine bug is only a tiny problem that the error message says -1 instead of 0. Your script is buggy. You are attempting to call 'closemenu(topmenu)' when there is no menu open. Like I said, this is probably because the onkeypress script is being called again while " leave game menu" is running.
_________________
"It is so great it is insanely great."
Back to top
View user's profile Send private message Send e-mail
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Wed May 12, 2010 10:59 pm    Post subject: Since January... I still have the same problem... Reply with quote

I think my problem comes from a missunderstanding about how the menu commands works...

All right let's make some tests. Let's say that I would like to make a menu that pops up with the s key (it would be menu 11).

I would also like the player to leave menu 11 using the s key. I think I would need to checks if menu 11 is already launched so that the correct script applies.

If menu 11 is already launched, I would need to close it. And menu 11 has not been opened then it would be as the script runs.

Could somoene help me to put this in plotscript language?


Thanks in advance for the help!
_________________
It's time to make games!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
lazy msw188
Guest






PostPosted: Thu May 13, 2010 7:02 am    Post subject: Reply with quote

There are a couple other issues to take care of to be able to do this. The main ones are:

-Does menu 11 lead to other menues?
-If it does, should menu 11 stay in the background while these other menues are there, or does menu 11 go away when the other menues come?
-In both cases, what should happen when the player presses the 's' key if there is a menu that is NOT menu 11 on top of the screen?
Back to top
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Fri May 14, 2010 9:01 am    Post subject: Well it was just an example but... Reply with quote

My problem is the following

My main menu is menu 6. It pops up and disappears when I use the esc key

It is composed of 8 sub menus

Items
Accessories
Formation
Status
Technics
Puzzle
Save
Quit

Items opens the menu 2 items and menu 2 opens the menu use item or sort or items or rare items (it depends on how the player is chosing)

The player just like custom basic main menu use the space bar to valid choices and esc to came back to the previous menu.

I'm trying to implement that for the moment and the rest will come later.

Thanks for answering so quickly and good luck in making your game
_________________
It's time to make games!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Fri May 14, 2010 11:44 pm    Post subject: Help with menu item handling Reply with quote

I managed to solve the problem by myself.
reading the article at :

http://gilgamesh.hamsterrepublic.com/wiki/ohrrpgce/index.php/Why_does_my_on-keypress_script_freeze/produce_errors_when_I_hold_down_a_key%3F

The script does not overload anylonger but the menu handling problem is still accurate.


Code:

switch (escape behaviour) do, begin   

case (0) do, begin # go to the game menu

suspend player
suspend npcs

set variable (YourMoney, party money) # cherche combien on a d'argent
#game menu active:= true #make sure player keeps suspended
#wait (1)

fade screen out (0, 0, 0)
show backdrop (0)

set variable (YourM,current map)  #permet d'enregistrer notre position dans le jeu
set variable (YourX,herox(me))
set variable (YourY,heroy(me))   

set variable (MyPicSet, get hero picture(me))  #permet d'enregistrer notre apparence
set variable (heropic1, get hero picture(1))
set variable (heropic2, get hero picture(2))
set variable (heropic3, get hero picture(3))


camera follows npc (0)
teleport to map (18, 2, 4)


set hero picture (me, 0) # hero 0 became invisible by default

if (hero by slot (1) <> -1) then, begin #  if slot (1) is occupied
set hero picture (1, 0)
end

if (hero by slot (2) <> -1) then, begin #  if slot (2) is occupied
set hero picture (2, 0)
end

if (hero by slot (3) <> -1) then, begin #  if slot (3) is occupied
set hero picture (3, 0)
end

$20= "P.Good" #chance par défaut enlevé plus tard


# string 8 et 11 servent déjà à afficher la magie dans les combats pour hakkai et sanzo réutilisés
# pour la chance et la magie dans le menu!

string from textbox (8, 53, 0) #text box 53 L0 -> chance
string from text box (11,53, 1) #text box 53 L1 -> money
show string at (8, 167, 18)
show string at (11, 167, 28)
set tag (tag : game menu launched, on)

open menu (6)
fade screen in
show map

resume player
resume npcs

end# end for the case

end #end fot the switch
end #end for the if keypress esc



My problem is linked with menu handling. I think I should re-implement every controls
By now menu my menu items are of type 4 (run script) and when the player chooses it launches
another script.

The trouble is that I'm using an menu map and I've got many things to change as far
as map appeareance and player actions on screen are concerned. Deep key
re-implementation would be what I need but I don't see very well where to start...

Let's start with the item menu

When the player choose items it launches the items script above.
Code:


#------------------------------------------------------------------------------
# item menu
plotscript, item menu, begin

fade screen out (0,0,0)

hide string (11) # hide luck and yens infos not in status menu
hide string (8)
close menu (top menu) # close previous menu : main menu 6

$0="Items"

string from textbox (1, 53, 2) #text box 53 L2 is for menu names
show string at (1, 17, 21) # Sub menu name location

escape behaviour:=2 #gives correct behaviour for escape key so that the player can leave without any pbs
wait(1) #very very important


open menu (2) #open item menu
wait (2)  #make sure menu already poped up when screen goes back to normal
open menu (8) #menu use item activé par défaut
wait (4)
variable (handle)
handle:= find menu ID (2) # menu 2 desactivé
set menu bit (handle, menubit:no controls, off)

fade screen in

end #end for the plotscript
#------------------------------------------------------------------------------



Here I need several controls

-> arrow keys (for the player to choose)
-> space key to valid
-> esc to go back to the menu 6


If I leave things as they are with non re-implemented key I'm afraid that script overloading
problems may come again

Could somoene help me by explaining again how to move THROUGH plotscripting from one
item menu to another one? There's seems to be a large choice of commands about menu items
: how do I choose the one I need?


I think I've understood how to move how to move from one
menu to another using the handling variable)

As always thanks a lot for helping and advice
_________________
It's time to make games!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
bis_senchi




Joined: 08 Jun 2004
Posts: 460
Location: Reims, France

PostPosted: Sun May 16, 2010 12:44 am    Post subject: Finally after some tests I managed to solve my problem Reply with quote

After checking in the plotscript dictionnary I managed to figure out why hspeak has complained

top menu can be used only when there's only one menu.

The switch command will allow me to adapt key behaviour with the previous key pressed.
_________________
It's time to make games!
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Castle Paradox Forum Index -> HELP! All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group