Post new topic    
Page 1, 2  »
Liquid Metal Slime
Send private message
Two Issues with Custom Menu 
 PostFri Apr 25, 2014 3:52 pm
Send private message Reply with quote
I have a pretty basic custom menu that works well, but I'm trying to get a few kinks out of it.

First, I can almost guarantee that I'm not writing this the most efficient way. If you have any suggestions just let me know.

Here are the issues:

1) When you close the menu with ESC, it will occasionally bring the menu right back up as opposed to properly closing out of it.

2) You can occasionally make part of the menu open while the hero is walking.

Both of these issues have pretty rare occurrences, but they happen nonetheless. I'd like to fix them if at all possible. Any help would be appreciated.

Code:
plotscript,menu,begin
   if (current text box == -1) then (
      free slice (menuslice)
      variable (i)
      for (i,10,18,1) do (
         clear string (i)
      )
      if (hero is walking (hero:Fred) == false) then (
         if (key is pressed (key: esc), or, key is pressed (key: alt)) then (
            suspend player
            menuslice := load slice collection (4)
            flvl := get hero level (find hero(hero:Fred))
            fmc := get hero stat (find hero(hero:Fred),stat:Mastery)
            fmm := get hero stat (find hero(hero:Fred),stat:Mastery,maximum stat)
            fhc := get hero stat (find hero(hero:fred),stat:Health)
            fhm := get hero stat (find hero(hero:fred),stat:Health,maximum stat)
            fexp := experience to next level (find hero(hero:Fred))
            pmon := party money
            append number (10,flvl)
            append number (11,fmc)
            append number (12,fhc)
            append number (13,fexp)
            append number (14,fmm)
            append number (15,fhm)
            append number (18,pmon)
            $16 ="/"
            $17 ="/"
            11 $+ 16
            11 $+ 14
            12 $+ 17
            12 $+ 15
            show string at (10,105,10)
            show string at (11,120,30)
            show string at (12,115,20)
            show string at (13,160,40)
            show string at (18,260,190)
            open menu (0)
            while (key is pressed (key: esc), or, key is pressed (key: alt)) do (
               wait (1)
            )
            resume player
         )
      )
   )
   wait for all
end

plotscript,cmenu,begin
   free slice (menuslice)
   variable (i)
   for (i,10,18,1) do (
      clear string (i)
   )
   wait for all
end

Cornbread Chemist
Slime Knight
Send private message
 
 PostFri Apr 25, 2014 4:30 pm
Send private message Reply with quote
Quote:
1) When you close the menu with ESC, it will occasionally bring the menu right back up as opposed to properly closing out of it.

I feel like I've had this issue before, but I'm not entirely sure I remember the issue. Is it possible that the script is being called twice (perhaps from Esc or Alt being held an extra second), and delayed until the first call is ended (ie exiting the main menu)?
Red Slime
Send private message
 
 PostFri Apr 25, 2014 4:31 pm
Send private message Reply with quote
Well, I've never used custom menus but I have a couple of suggestions anyway.

#1. The script "hero is walking" is one of those position-in-the-caterpillar kinda scripts whereas you are passing it an enum. I'm assuming Fred is hero numero zero and thus your script should work in general (since it would be basically the equivalent of saying "hero is walking (0)" which is the same as "hero is walking (me)" I believe), but that could somehow be where the menu-popping-up-during-walking error is coming in.

#2. I'm guessing "open menu" freezes the game while you mess around in there and then returns to script execution when you are finished (again, never used 'em myself). After your open menu call you have a short wait based on whether or not the player is still holding down certain keys. You may want to just add another "universal wait" (say wait(3)) after that one before resuming player control. That way there's just a slight extra bit of wait time before your scripts start looking for player input again after the menu closes. I usually do this for my custom HUD stuff and it works pretty well.

#3. You are displaying your strings directly using the "show string at" script. Since you are already loading up a slice collection, wouldn't it be easier to position the strings by creating text slices and then updating those with the string information? That way you don't have to do exact "pixel-by-pixel" placement of the strings in the script itself and you don't have to do that annoying string cleanup each time.
Liquid Metal Slime
Send private message
 
 PostFri Apr 25, 2014 6:43 pm
Send private message Reply with quote
sotrain515 wrote:
Well, I've never used custom menus but I have a couple of suggestions anyway.

#3. You are displaying your strings directly using the "show string at" script. Since you are already loading up a slice collection, wouldn't it be easier to position the strings by creating text slices and then updating those with the string information? That way you don't have to do exact "pixel-by-pixel" placement of the strings in the script itself and you don't have to do that annoying string cleanup each time.


I tried the things you suggested and it doesn't seem to make a difference, but perhaps I put it in the wrong place.

As for what you suggested in #3, that sounds great but is beyond my scripting know-how. I'd be happy to implement it if someone could help walk me through it.
Cornbread Chemist
Red Slime
Send private message
 
 PostFri Apr 25, 2014 8:15 pm
Send private message Reply with quote
It's not too hard (though I sure did end up writing a wall of text).

You have a slice collection loading already so I assume you know generally how they work. Next thing you would do is open that collection up in the editor and create some new text slices. I would split them up into about four per stat, let's say, to allow for "literals". For example, your HP field could be four text slices that would have the text "HP:" "##" "/" and "##". The two "##" slices would hold the info you are pulling when the script is called. It's helpful to fill them out with dummy characters like that when building the collection so you can see how it will look when the data is in there.

Next orient the text slices however you want (above/below your existing slices and with the x/y position you desire). Then give the ones that will have data (the two "##" slices) lookup codes in keeping with your existing nomenclature. For our example, let's say you chose the name sl:chptext for your current hp stat and sl:mhptext for your max hp stat.

Next, let's look at your existing code:

Code:
menuslice := load slice collection (4)

fhc := get hero stat (find hero(hero:fred),stat:Health)
fhm := get hero stat (find hero(hero:fred),stat:Health,maximum stat)

append number (12,fhc)
append number (15,fhm)

$17 ="/"
12 $+ 17
12 $+ 15

show string at (12,115,20)


This is how you are currently displaying a string "##/##" to represent the HP of your guy.

Here is how it will look in the new code (this is after you've created your text slices and exported a new .hsi file):

Code:
menuslice := load slice collection (4)

fhc := get hero stat (find hero(hero:fred),stat:Health)
fhm := get hero stat (find hero(hero:fred),stat:Health,maximum stat)

$1 = ""
append number (1,fhc)
set slice text(lookup slice(sl:chptext, menuslice), 1)

$1 = ""
append number (1,fhm)
set slice text(lookup slice(sl:mhptext, menuslice), 1)


Notice you can get away with reusing a single string simply clearing it each time you want to set it to something else. And when you're done you don't have to worry about what information is in it, since you aren't showing it anywhere on the screen.

Disclaimer (same as the one I just wrote for sheamkennedy, heh): Basically I am just writing all this code freehand and you may need to clean it up somewhat before it'll work properly.
Liquid Metal Slime
Send private message
 
 PostSat Apr 26, 2014 1:58 pm
Send private message Reply with quote
Thanks! Works great!

I think I figured out what was causing issue #1 and #2 as well. I removed the "wait for alls" at the end of each script and it appears to not have the occasionally hiccups anymore. Further testing will be required to make sure, but that's what it looks like for now.
Cornbread Chemist
Metal King Slime
Send private message
 
 PostSun Apr 27, 2014 9:11 am
Send private message Reply with quote
Yes, that "wait for all" would have caused that gitch. Also in this case the "while(key is pressed...) do (wait(1))" loop should be unnecessary because of the openmenu.

Incidentally, if you noticed a problem where alt causes a problem but esc doesn't then you've encountered a different problem having to do with key:filtered alt.

Some suggestions for simplifying:

If you are using a nightly build then you can throw away the stuff at the beginning of the script, and make the script the "menu action plotscript" instead (in the special script menu).

This is irrelevant since sotrain has you using text slices instead, but you can rewrite
Code:
clear string(12)
clear string(15)
append number (12,fhc)
append number (15,fhm)

$17 ="/"
12 $+ 17
12 $+ 15

as
Code:
clear string(12)
append number (12,fhc)
$12 +"/"
append number (12,fhm)

and if you're using a nightly you can write
Code:
$15="%d/%d"
string sprintf(12, 15, fhc, fmc)

%d means decimal number.
Liquid Metal Slime
Send private message
 
 PostWed May 07, 2014 5:13 pm
Send private message Reply with quote
Thanks for the info! I'm still having an issue with the behavior of the ALT key though. Pulling up the menu via escape works great, but doing so by ALT 9/10 closes out the menu as fast as it opens it.

Is there any way to ensure that ALT will wait for the menu to actually open and not close it prematurely? I wouldn't be opposed to omitting the ALT key from opening the menu either, but I'm not sure how to make that work.
Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostWed May 07, 2014 6:33 pm
Send private message Reply with quote
Change this line:

Code:

if (key is pressed (key: esc), or, key is pressed (key: alt)) then (


TO be like this

Code:

if (keyval(key:esc) > 1 || keyval(key:alt) > 1) then (


using keyval() > 1 will make the key checking less sensitive to repeats.

changing ,or, to || doesn't affect the bug, I just think || is better for various reasons.
Liquid Metal Slime
Send private message
 
 PostWed May 07, 2014 7:37 pm
Send private message Reply with quote
Thanks, but it looks like I'm still having the issue. Here is the updated script:

Code:
plotscript,menu,begin
   if (string is visible (0)) then (
      set tag (298,on)
      clear string (0)
      clear string (1)
   )
   if (current text box == -1) then (
      free slice (menuslice)
      if (hero is walking (hero:Fred) == false) then (
          if (keyval(key:esc) > 1 || keyval(key:alt) > 1) then (
            suspend player
            menuslice := load slice collection (4)
            flvl := get hero level (find hero(hero:Fred))
            fmc := get hero stat (find hero(hero:Fred),stat:Mastery)
            fmm := get hero stat (find hero(hero:Fred),stat:Mastery,maximum stat)
            fhc := get hero stat (find hero(hero:fred),stat:Health)
            fhm := get hero stat (find hero(hero:fred),stat:Health,maximum stat)
            fexp := experience to next level (find hero(hero:Fred))
            pmon := party money
            $10 = ""
            append number (10,flvl)
            set slice text (lookup slice(sli:fredlevel,menuslice),10)
            $10 = ""            
            append number (10,fmc)
            set slice text (lookupslice (sli:fredcurms,menuslice),10)
            $10 = ""            
            append number (10,fhc)
            set slice text (lookupslice (sli:fredcurhp,menuslice),10)
            $10 = ""            
            append number (10,fexp)
            set slice text (lookupslice (sli:fredxptolvl,menuslice),10)
            $10 = ""            
            append number (10,fmm)
            set slice text (lookupslice (sli:fredmaxms,menuslice),10)
            $10 = ""            
            append number (10,fhm)
            set slice text (lookupslice (sli:fredmaxhp,menuslice),10)
            $10 = ""            
            append number (10,pmon)
            set slice text (lookupslice(sli:coins,menuslice),10)
            $10 = ""               
            open menu (0)
            while (key is pressed (key: Esc),or,key is pressed (key: Alt)) do (
               wait (1)
            )
            resume player
         )
      )
   )
end


I don't believe any other scripts are being run during this time.
Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostWed May 07, 2014 7:51 pm
Send private message Reply with quote
Oh, wait. I missed the other part at the end:

Code:

            while (key is pressed (key: Esc),or,key is pressed (key: Alt)) do (
               wait (1)
            )


I am actually not sure what this part is for. I am guessing maybe it was an attempt to work around the problem you are describing? At any rate, I suggest removing it.

Code:

open menu (0)


Does this menu have the bitset that allows gameplay and scripts?

Code:

if (hero is walking (hero:Fred) == false) then (


If this works it is only by lucky coincidence. It should be:

Code:

if (hero is walking (rank in caterpillar(hero:Fred)) == false) then (


Or better yet, here is a version that works even if Fred isn't in the part at all, and is simpler too:

Code:

if (hero is walking (me) == false) then (


See http://rpg.hamsterrepublic.com/ohrrpgce/Ways_to_refer_to_a_hero_in_a_script for an explanation of why "hero is walking (hero:Fred)" is wrong but sometimes seems to work.
Liquid Metal Slime
Send private message
 
 PostWed May 07, 2014 9:18 pm
Send private message Reply with quote
Thanks for the info. I did everything you suggested but I'm still having the same problem unfortunately. The allow gameplay bitset was NOT on, but I tried it both ways just to see and it didn't make a difference.

Here is the updated script:

Code:
plotscript,menu,begin
   if (string is visible (0)) then (
      set tag (298,on)
      clear string (0)
      clear string (1)
   )
   if (current text box == -1) then (
      free slice (menuslice)
       if (hero is walking (me) == false) then (
          if (keyval(key:esc) > 1 || keyval(key:alt) > 1) then (
            suspend player
            menuslice := load slice collection (4)
            flvl := get hero level (find hero(hero:Fred))
            fmc := get hero stat (find hero(hero:Fred),stat:Mastery)
            fmm := get hero stat (find hero(hero:Fred),stat:Mastery,maximum stat)
            fhc := get hero stat (find hero(hero:fred),stat:Health)
            fhm := get hero stat (find hero(hero:fred),stat:Health,maximum stat)
            fexp := experience to next level (find hero(hero:Fred))
            pmon := party money
            $10 = ""
            append number (10,flvl)
            set slice text (lookup slice(sli:fredlevel,menuslice),10)
            $10 = ""            
            append number (10,fmc)
            set slice text (lookupslice (sli:fredcurms,menuslice),10)
            $10 = ""            
            append number (10,fhc)
            set slice text (lookupslice (sli:fredcurhp,menuslice),10)
            $10 = ""            
            append number (10,fexp)
            set slice text (lookupslice (sli:fredxptolvl,menuslice),10)
            $10 = ""            
            append number (10,fmm)
            set slice text (lookupslice (sli:fredmaxms,menuslice),10)
            $10 = ""            
            append number (10,fhm)
            set slice text (lookupslice (sli:fredmaxhp,menuslice),10)
            $10 = ""            
            append number (10,pmon)
            set slice text (lookupslice(sli:coins,menuslice),10)
            $10 = ""               
            open menu (0)
            resume player
         )
      )
   )
end

Cornbread Chemist
Liquid Metal King Slime
Send private message
 
 PostWed May 07, 2014 9:33 pm
Send private message Reply with quote
Strange....


How is this script triggered? Is it an on-keypress script?
Metal King Slime
Send private message
 
 PostThu May 08, 2014 4:06 am
Send private message Reply with quote
This is exactly the issue I mentioned earlier with key:filtered alt. The menu doesn't open or close when you press alt, it does so when you release alt. This is indicated with a special separate scancode called key:filteredalt. The reason is so that window manager shortcuts like alt+tab, alt+left, alt+enter, etc, can be ignored and don't trigger an action in-game.

I regret adding key:filteredalt, as it's created a nuisance and probably breaks old games that try to prevent the menu from opening.

In this case when you press down alt openmenu is called, but when you release alt the menu perceives an alt key press and closes it again. Just replace key:alt with key:filteredalt.

Also, the suspendplayer and resumeplayer do nothing.

Incidentally, if this script was an on-menu instead of on-keypress script you would have avoided this problem as well as the other bug James mentioned. Of course you may not be using nightlies, so no jab at you.
Liquid Metal Slime
Send private message
 
 PostThu May 08, 2014 1:02 pm
Send private message Reply with quote
Thanks guys, filteredalt fixed it. I am not using the nightlies because I wanted to keep Ruin on the latest stable release to avoid any potential playability issues using the nightlies (once it is released, of course).
Cornbread Chemist
Display posts from previous:
Page 1, 2  »