Official ScriptUO EasyUO Scripts > Scripting Tutorials

New Menu Code and how to adapt old scripts

(1/4) > >>

Gaderian:
This will have several parts to it which I will post below.
This is Part 1 with a general overview.
Part 2 will have code comparisons of the old vs. New code for menu's.
Part 3 will have "How To" examples to accomplish things.

I am not covering how to use the menu creation tool that Cerveza covered in the Sticky Menu post.

Menu: Part 1
It has been a while since the menu code was updated. At first it seemed a little confusing to implement because I had always used the Menu Designer and the old version of EUO. I made very few modifications without that tool.

There is no tool to create the new menus and it has 2 affects:
1) The nice new features are not being used by new scripts
2) Old scripts and styles are often broken

There are not a lot of examples on how to write good menu code now. I have been offering to modify old menu code that isn't working in scripts for others and decided that a simple guide might help.

What happens to old menu code? Does it still work or simply break scripts?

The old menu code can still work and most of it's features are still there. That is the good news. The bad part of this is that the rules are more strict now. If the original script didn't follow the current (revised) rules, then it is very easy for the menu to break. It will seem like a script will either not work or work intermittently and require stopping and restarting to get it to function again.

My goal is to make clear the rules that a programmer needs to follow and show some common ways to get around what used to be "the method" to have dynamic menus.

The old menu code would allow a single menu vs. the new menu code allows multiple menus.
This makes the new menu code more efficient and flexible than the old way.

There is 1 basic rule:
Each element on the menus must have a unique name. (Re-using names will cause it to break.)

Functional Changes with new menu system:
menu shape is really emulated via "menu image... "
Old menu creation commands vs. New menu creation commands
 New menu commands create forms that are 10 pixels larger in both the X and Y axis than the original commands. This leaves additional space on the right edge and bottom edge of menu's. If you are really dependent on screen real estate - this may affect your overall screen layout. Offsets for where everything is placed is correct, just that the form is larger.

Restrictions:
menu shape can't have dash lines or rounded corners
menu transparent only applies to old menu code
menu font transparent only applies to old menu code

A few commands no longer exist:
menu image pixline (this could be accomplished with a sub to process the data to draw the line with pixel/line statements)
menu hideeuo

New additions:
Panel
Radiobutton
pushdef
popdef
setdef
getdef
setprop
Every element has a parent (along with other new properties)


Logic changes:
If a script used multiple menu's in the past, it was done with "effects". Maybe it would create a menu for setup, then clear it and recreate the menu for running the script.
It could have a button to go to the setup and what would be done:
 -clear the running script menu
 -rewrite all the setup elements
 -get the information
 -clear the setup menu
 -rewrite the running script menu all fresh
Separate forms (menus) can be created now and simply use "setprop [formname] visible [#true|#false]" to hide one of the other to accomplish the former behavior. The good part is that the menus do not need to be recreated, but can simply be updated and change the visible setting.

The old system could change a Text element with 'menu set [text]', but all too often the script would delete the former element and create a new element in it's place with the same name. (This is the most common violation of the new rule to have unique element names, by the way, and usually makes the menu "break".)

If the old system needed to display some message, an ad hoc 'menu text' element was defined and then subsequently deleted. It would be recreated the next time the message
was displayed.
Similar code was in use often to make buttons, then change the button place function by deleting/creating a new button in it's place.

This method of delete/create violates the unique element name requirement now.

How to revise the delete/create code?

There are several functional examples in a post below, but here is the concept:

Create a subroutine to create all the menu elements  that will be used in the script.
This is nice because all restructure changes in one place, too.

Now set the visibility #false on each of the elements you want to use later, but don't want displayed all the time:

--- Code: easyuo ---menu button Mybutton 10 10 30 20 My Buttonmenu setprop Mybutton visible #false
Later in the routine where you want to bring forward the element, you can set the element
you want to turn off to invisible, while changing the "hidden" element to be visible:

--- Code: easyuo ---menu setprop ActionButton visible #falsemenu setprop Mybutton visible #true ... Do some stuff in your script ... ; restore the buttons:menu setprop Mybutton visible #falsemenu setprop Actionbutton visible #true
Former "#menures = Closed" value only works for form0.
All other forms when the "X" at the top right is clicked will set #menures = [formname]

Old code anamolies:
menu clear
 Deletes all forms except for form0 (the classic menu)!
 sets #menubutton to nothing (used to be N/A)
 running old scripts require setting #menubutton to N/A after menu clear statements to behave the same as previously.
Menu delete/Menu [create] looks like it worked, but clicking on a button is unresponsive  use the visible #false/#true method to fix it

Color Rules and Changes:
Named colors of Windows 'Theme' only works with old method of creating windows and the Pascal named colors do not work with new menu
Attached to this post is a subroutine that can be called to set colors to variable names.
 -addresses many usable colors (including a direct correlation to the old color values).
 -creates all the windows 'theme' values as variables with settings for a default windows theme. If you want to change your theme colors you can adjust the
settings in the ColorNameSub.txt routine.
Save the attached file in your Easyuo directory and call it during script setup to make the color variables available to your script.
Where the Easyuo commands could reference "red" or "black", now you would reference a variable named "%red" or "%black" respectively. Many colors are included in the subroutine.

Groupings by new property Parent:
All elements have a parent. It could be a form or a panel.
The parent is inherited by the current default parent.
 -The default parent is either the most recently created form or panel or established using "setdef parent [form or panel name]"
 -Changed after element creation using "setprop [element] parent [form or panel name]"
All Radio buttons in the same parent - only 1 can be 'checked', others in the same parent are automatically turned off. So in order to use multiple groups of radio buttons, use panels to keep each group of radio buttons.

Menu font deprecated and defaults expanded to include other properties:
menu setdef replaces all but "menu font transparent"
menu getdef allows seeing the settings

Pushdef/Popdef allows protected logic elsewhere so you can have your own settings.
menu pushdef
menu popdef
If you will create your own menu to go with a routine, you would structure it enveloped inside the pushdef/popdef commands.
Instead of using Display, you could create a menu form that displays the message. This would work in called libraries and the menu can live after the library call is done.

Gaderian:
Part 2 Menu Code: Compare Old Syntax vs. Modern Syntax
New menu system concepts/requirements
 Each element must have a unique name.
 Each element has a parent.
         The parent is inherited from the last 'form' or 'panel' created, the current "menu setdef parent" command in effect, or set after creation via "menu setprop [element name] parent [parent name]".
 Top reasons old menu code breaks:
  - reusing element names to create additional elements
  - #menubutton <> N/A following command "menu clear"
 Former named colors no longer are honored in new menus.
  -
Obsolete commands

--- Code: easyuo --- menu image pixline - was rarely used, but can be accomplished with a subroutine menu hideeuo - no longer present menu font transparent - deprecatedNew commands

--- Code: easyuo --- menu form menu panel menu getdef menu setdef menu setprop - change 1 property pair of an item menu pushdef menu popdef menu radio
Limited commands
 Some commands are limited to the original method.
 These would only affect 'form0' which is the name given to any legacy menu code for it's form.

--- Code: easyuo --- menu clear * Note changed behavior below menu window title menu window size menu show menu window transparent
Changed behavior commands:

--- Code: easyuo --- menu delete - the old method to delete and recreate a same name element breaks menu code. Each created menu item needs a unique name. menu shape - no longer allows some effects (dotted/dash fill and rounded corners)      - line effects could be done with sub routines      - rounded corners might be possible with clever effects, but are no longer available as internal options Using the Window X in the top right corner of a standard window sets #menures = closed for form0, but the form name on other menus that are closed menu clear - sets #menubutton to nothing (used to be N/A)          - deletes all forms. There was only a single form (form0) in legacy scripting. New form sizes are 10 pixels larger (vertical and horizontal) than 'menu Window Size' command
Commands that need no update (unless element names are inappropriately replicated):

--- Code: easyuo --- menu Activate [name] menu Button [name] [width] [height] [text] menu Check {name} {x} {y} {width} {height} {checked} {text} menu Combo Create {name} {x} {y} {width} menu Combo Add {name} {text} menu Combo SELECT {name} {index} menu Edit {name} {x} {y} {width} {text} menu Get [name] menu GetNum {name} {default} menu List Create {name} {x} {y} {width} {height} menu List Add {name} {string} menu List Select {list name} {item number} menu Image Create {name} {x} {y} {width} {height} menu Image Ellipse {name} {x1} {y1} {x2} {y2} {color} {fill} [width] menu Image File {name} {x} {y} {filename} menu Image FloodFill {name} {x} {y} {color} menu Image Line {name} {x1} {y1} {x2} {y2} {color} [width] menu Image Pix {name} {x} {y} {color} menu Image Pos {name} x y width height menu Image Rectangle [element unique name] relative-x1 relative-y1 relative-x2 relative-y2 color [fill: #false leaves internal clear/transparent, anything else fills with color] [width: if fill = #false, then a line width may be set] menu Set [element] [value] *Note: See menu setprop in New Commands section for a more flexible command menu Text [element unique name] left top [text]
Equivalent coding for all commands:

--- Code: easyuo ---  ; Primarily alphabetized by the original statement or inserted alphabetically as the new statement.menu Activate [name]                                                    menu activate [element's unique name]                                                                             ; brings forward along with it's parent (form and/or panel) (gives focus?)menu Button [name] [width] [height] [text]                              menu button [button unique name] left top height width  [button label]menu Check {name} {x} {y} {width} {height} {checked} {text}             menu check [element unique name] left top width height [checked:#true/#false]                                                                                   [text...]menu Clear                                                              menu delete form0 (Note: all forms are actually deleted with the "menu clear")menu Combo Add {name} {text}                                            menu combo add [element unique name] [text entry...]menu Combo Create {name} {x} {y} {width}                                menu combo create [element unique name] left top widthmenu Combo SELECT {name} {index}                                        menu combo select [element unique name] indexmenu Delete {name}                                                      menu delete [element's unique name]menu Edit {name} {x} {y} {width} {text}                                 menu edit [element unique name] left top width height [text...][new command]                                                           menu getdef [option name: will be returned in #menures]menu Font Align { left|right|center }                                   menu setdef alignment [ 0|1|2 ] ; 0 = left, 1 = right, 2 = centermenu Font BGColor [color-descriptor]                                    menu setdef color $BBGGRRmenu Font Color [color-descriptor]                                      menu setdef fontcolor $BBGGRRmenu Font Name  [font-name]                                             menu setdef fontname [fontname]menu Font Size  {point-size}                                            menu setdef fontsize [pointsize]menu Font Style {b|i|u|s}                                               menu setdef fontstyle {sum of style attributes}                                                                              ; 1=bold, 2=italic, 4=underline, 8=strikeoutmenu Font Transparent [ #true|#false ]                                 -no equivalent: only works with form0[new command]                                                           menu form [form unique name] left top width height [text]                                                                             Creates a new window which is 10 pixels wider and taller than old                                                                             measurements. It is set to "visible #false" by default, so needs to be                                                                              made visible with "menu setprop".menu Get [name]                                                         menu get [element unique name] : sets #menuresmenu GetNum {name} {default}                                            menu GetNum {name} {default}menu Hide                                                               menu setprop [form unique name] visible #falsemenu HideEUO                                                           -No longer functionsmenu List Add {name} {string}                                           menu list add [element unique name] [text...]menu List Create {name} {x} {y} {width} {height}                        menu list create [element unique name] left top width heightmenu List Select {list name} {item number}                              menu list select [element unique name] indexmenu Image Create {name} {x} {y} {width} {height}                       menu image create [element unique name] left top width height                                                                             All the elements created within the image reference the image_unique_name                                                                             and have relative x/y positions within it's canvasmenu Image Ellipse {name} {x1} {y1} {x2} {y2} {color} {fill} [width]    menu image ellipse [element unique name] left top width height color fill widthmenu Image File {name} {x} {y} {filename}                               menu image file [element unique name] x y [external filename]                                                                             ; external filename can be one of: *.jpg, *.bmp, *.gifmenu Image FloodFill {name} {x} {y} {color}                             menu image floodfill [element unique name] relative-x relative-y colormenu Image Line {name} {x1} {y1} {x2} {y2} {color} [width]              menu image line [element unique name] x1 y1 x2 y2 color widthmenu Image Pix {name} {x} {y} {color}                                   menu image pix [element unique name] x y colormenu Image Pixline {name} {x} {y} {data}                               -no equivalentmenu Image Pos {name} x y width height                                  menu image pos [element unique name] left top width height                                                                             moves or resizes the imagemenu Image Rectangle {name} {x1} {y1} {x2} {y2} {color} {fill} [width]  menu image rectangle [element unique name] x1 y1 width height color fill width                                                                             ; [fill: #false means transparent, otherwise fill is a color]                                                                             ; [width: if fill = #false, then a line width may be set][new command]                                                           menu panel [panel unique name] left top height width[new command]                                                           menu popdef[new command]                                                           menu pushdef[new command]                                                           menu radio [radio_unique_name] left top width height [checked: #true/#false] [labeled text...]menu Set [element] [value]                                              menu set [unique-element-name] [value]                                                                         menu setprop [unique-element-name] [checked #true|#false] ; For Check and Radio                                                                        menu setprop {unique-element-name] [text 'value'][new command - but replaces some old]                                   menu setdef                                                                             alignment [0|1|2] 0 = left, 1 = right, 2 = center                                                                             color     $BBGGRR                                                                             fontcolor $BBGGRR                                                                             fontname {font name}                                                                             fontsize {point size of font}                                                                             fontstyle 1=bold, 2=italic, 4=underline, 8=strikeout                                                                             parent [parent-name]                                                                        menu setprop [element's unique name] [option #spc value pair]                                                                             alignment: RADIO,CHECK,TEXT,                                        DEFAULT                                                                             color:     RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,FORM,PANEL,      DEFAULT                                                                             checked:   RADIO,CHECK                                                                             enabled:   RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,FORM,PANEL,IMAGE                                                                             fontcolor: RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,                 DEFAULT                                                                             fontname:  RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,                 DEFAULT                                                                             fontsize:  RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,                 DEFAULT                                                                             fontstyle: RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,                 DEFAULT                                                                             height:    RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,FORM,PANEL,IMAGE                                                                             left:      RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,FORM,PANEL,IMAGE                                                                             parent:    RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,     PANEL,IMAGE,DEFAULT                                                                             text:      RADIO,CHECK TEXT,BUTTON,EDIT,           FORM,                                                                             tooltip:   RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,FORM,PANEL,IMAGE                                                                             top:       RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,FORM,PANEL,IMAGE                                                                             visible:   RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,FORM,PANEL,IMAGE                                                                             width:     RADIO,CHECK,TEXT,BUTTON,EDIT,COMBO,LIST,FORM,PANEL,IMAGE        menu Shape {name} {x1} {y1} {x2} {y2} {shapetype}                       menu Shape {element unique name} {left} {top} {width} {height} {shapetype}            {linetype} {linewidth} {linecolor} {filltype} {fillcolor}               {linetype} {linewidth} {linecolor} {filltype} {fillcolor}                                                                                    shapetype 1 (circle), 2 (ellipse), 3|4 (rectangle), 5|6 (square)                                                                                    linetype 1 (clear), 2-7 (solid)                                                                                    filltype 1-6,8 (clear), 7 (solid)menu Show                                                               menu setprop [form unique name] visible #truemenu Text [element unique name] left top [text]                         menu text [element unique name] left top [text...] ; menu Window commands can be set in a single command and subsequently adjusted by menu setprop commands. See "menu form" above.menu Window Color  {color-descriptor}                                   menu setprop [form unique name] color $BBGGRR                                                                        ; Window color is *NOT* inherited from "menu setdef color",                                                                                                                      ; so must be set after creationmenu Window Size {width} {height}                                       menu setprop [form unique name] width [width] (old {width} = [width] - 10)                                                                        menu setprop [form unique name] height [height] (old {height} = [height] - 10)menu Window Title {title}                                               menu setprop [form unique name] text [title]menu Window Transparent [ opacity percentile ]                         -No equivalent, but now only works on form0
Note: menu setprop works for 1 keyword/value pair. Use separate statements for each setting.

Gaderian:
Part 3: How To examples
Basic Menu

--- Code: easyuo ---; Demonstrate the comparison of the original menu method vs. the new menu method to  make a simple menu; comment out the "goto" statement method you don't want to try;goto OriginalMenugoto NewMenuhalt NewMenu:call ColorNameSub.txtgosub showEUOMenuNewwhile #menubutton <> EUOButton1 && #menubutton <> FormEquivalent ; When using X to close the menu... #menubutton set to [form name] { wait 1 }haltsub showEUOMenuNew  menu form FormEquivalent 0 0 210 163 Equivalent Form  menu setprop FormEquivalent color %BtnFace  menu setdef alignment Right  menu setdef fontname MS Sans Serif  menu setdef fontsize 8  menu setdef fontstyle 0  menu setdef fontcolor %Black  menu Button EUOButton1 10 10 50 25 Quit  menu setprop FormEquivalent visible #true         1return OriginalMenu:gosub showEUOMenuOriginalwhile #menubutton <> EUOButton1 && #menubutton <> CLOSED ; When using X to close the menu... #menubutton set to CLOSED { wait 1 }haltsub showEUOMenuOriginal  menu Clear  menu Window Title Original Menu  menu Window Color BtnFace  menu Window Size 210 163           1  menu Font Transparent #true  menu Font Align Right  menu Font Name MS Sans Serif  menu Font Size 8  menu Font Style  menu Font Color Black  menu Button EUOButton1 10 10 50 25 Quit  menu Show 0 0return

Fix Delete/Re-Create Buttons (or other elements)
If either multiple elements are created with the same name or deleted and recreated, there is unexpected behavior. A button will work once, but after the delete/recreate it will become unresponsive because of the unique name violation.

--- Code: easyuo ---; How to reuse a button (or another element during a subroutine); This will create 2 buttons in the same place in the main menu section, but; the BtnResume is not initially visible. During the sub BtnPause, the BtnPause ; will be set to "visible #false" and BtnResume is set to "visible #true".; This gives the effect of deleting BtnPause and creating BtnResume, but doesn't violate creating 2 elements with the same name.; If a menu does the Delete/Re-Create BtnPause logic, then it will successfully pause the first time, but on subsequent ; Pause attempts the button seems to be ignored. This style of logic will correct that behavior.call ColorNameSub.txtgosub showEUOMenuNewset #menubutton N/A ; we want a known value for #menubutton... original set to N/A with "menu clear" so this is as good as any valuegosub CheckButtons halt sub CheckButtons while #menubutton <> formEquivalent && #menubutton <> Quit  {  gosub #menubutton  }return sub showEUOMenuNew  menu form FormEquivalent 0 0 210 163 Equivalent Form  menu setprop FormEquivalent color %BtnFace  menu setdef alignment Right  menu setdef fontname MS Sans Serif  menu setdef fontsize 8  menu setdef fontstyle 0  menu setdef fontcolor %Black  menu Button Quit 10 10 50 25 Quit  menu Button BtnPause 10 50 50 25 Pause  menu Button BtnResume 10 50 50 25 Resume ; create Resume button for later  menu setprop BtnResume visible #false    ; set element invisible for later use  menu setprop FormEquivalent visible #true         1return sub BtnPause set #menubutton N/A menu setprop BtnPause visible #false ; hide Pause button menu setprop BtnResume visible #true ; show Resume button (in same place as pause button) while #menubutton = N/A  wait 1 menu setprop BtnResume visible #false ; hide Resume button menu setprop BtnPause visible #true   ; show Pause buttonreturn
Fix Delete/Re-Create Text elements
Labels ('menu text ...') may not display or if simply recreated over the top of the previous label, leaves residual text in the background.
Rather than delete the text element, create it during menu initialization and use the new "menu setprop ..." command to update it.
Note: Technically this could have also been done using the original "menu set" statement.

--- Code: easyuo ---; Demonstrate updating a text label using "menu setprop" to avoid unique element name violation with delete/recreate; The logic of the sub 'status' was modeled after MWinc Lumberjackercall ColorNameSub.txtgosub showEUOMenuNewset #menubutton N/A ; we want a known value for #menubutton... original set to N/A with "menu clear" so this is as good as any valueset %status Rungosub Statusgosub CheckButtonsset %status Quitgosub Statushalt sub CheckButtons while #menubutton <> formEquivalent && #menubutton <> Quit  {  gosub #menubutton  }return sub showEUOMenuNew  menu form FormEquivalent 0 0 210 163 Equivalent Form  menu setprop FormEquivalent color %BtnFace  menu setdef alignment Right  menu setdef fontname MS Sans Serif  menu setdef fontsize 8  menu setdef fontstyle 0  menu setdef fontcolor %Black  menu Button Quit 10 10 50 25 Quit  menu Button BtnPause 10 50 50 25 Pause  menu Button BtnResume 10 50 50 25 Resume ; create Resume button for later  menu setprop BtnResume visible #false    ; set element invisible for later use  menu text status 10 75 Status  menu setprop FormEquivalent visible #true  set %status Initializing  wait 20 ; pause for effect... to see label = "Status"  gosub Status  wait 20 ; pause for effect... to see label = "initializing" before changed to "run"return ;=============================================================================; Displays Status Of Script on Menusub status menu setdef fontcolor %blue if %status = Initializing  menu setprop status text Initializing... if %status = Quit  menu setprop status text Quitting... if %status = Run  menu setprop status text Running. if %status = Finding  menu setprop status text Finding Your Books.. if %status = Bookdone  menu setprop status text Books Found. if %status = Recall  menu setprop status text Recalling.. menu setdef fontcolor %yellowreturn
Dotted Lines (Approximation for menu shape to create dotted lines)
This is limited to horizontal or vertical lines. It would need trigonometry modifications to allow consistent lines at other slopes.

--- Code: easyuo ---menu form FormLines 0 0 255 255 Line Examplemenu setprop FormLines visible #trueset %name ImageLinesset %color 0 ; black against default grey background for example routinegosub Dotted_line %name , 1 , _  0  79 167   1 %color 3 hgosub Dotted_line %name , 2 , _   0 127 167   1 %color 3 hgosub Dotted_line %name , 3 , _  97   0   1  79 %color 3 vgosub Dotted_line %name , 4 , _ 167   0   1 255 %color 3 vgosub Dotted_line %name , 5 , _ 240   0   1 255 %color 3 vhalt ; shapename %1; x %2; y %3; x2 %4; height %5; color %6; interval %7; orientation = (h)orizontal|(v)erticalsub Dotted_line set %gl_shapename %1 set %gl_x %2 set %gl_y %3 set %gl_x2 %4 set %gl_y2 %5 set %gl_color %6 set %gl_interval %7 set %gl_orientation %8 if %gl_orientation = h  {  while %gl_x <= %gl_x2   {   menu shape %gl_shapename , %gl_x %gl_x %gl_y %gl_interval %gl_y2 3 7 1 %gl_color 2 0   set %gl_x %gl_x + ( %gl_interval * 2 )   }  } else  {  while %gl_y <= %gl_y2   {   menu shape %gl_shapename , %gl_y %gl_x %gl_y %gl_x2 %gl_interval 3 7 1 %gl_color 2 0   set %gl_y %gl_y + ( %gl_interval * 2 )   }  }return
New Radio Buttons (Panel and pushdef/popdef examples)
The new Radio Buttons work similar to a ComboBox (1 element active at a time), but have a different graphic/feel.
Each element has a property called "parent". All Radio Buttons in the same parent allow a single radio button to be active at anytime. When one is selected, the other radio buttons in the parent will be disabled ("checked #false" setting).

Pushdef and Popdef, a Panel and then Setdef can be used to create a radio button group that is isolated from others on the menu. Here is an example to setup 2 sets of Radio buttons:

--- Code: easyuo ---; Demonstrate creating 2 isolated groups of radio buttons in separate panels.; This also shows an example using pushdef/popdef/setdefcall ColorNameSub.txtgosub showEUOMenuNewset #menubutton N/A ; we want a known value for #menubutton... original set to N/A with "menu clear" so this is as good as any valueset %status Rungosub Statusgosub CheckButtons halt sub CheckButtons while #menubutton <> formEquivalent && #menubutton <> Quit  {  gosub #menubutton  menu get radingot1  if #menures = #true   menu setprop txt1 text radingot1  menu get radboard1  if #menures = #true   menu setprop txt1 text radboard1  menu get radsaltpeter1  if #menures = #true   menu setprop txt1 text radsaltpeter1  menu get radingot2  if #menures = #true   menu setprop txt2 text radingot2  menu get radboard2  if #menures = #true   menu setprop txt2 text radboard2  menu get radsaltpeter2  if #menures = #true   menu setprop txt2 text radsaltpeter2  }return sub showEUOMenuNew menu form FormEquivalent 0 0 210 163 Equivalent Form menu setprop FormEquivalent color %BtnFace menu setdef alignment Right menu setdef fontname MS Sans Serif menu setdef fontsize 8 menu setdef fontstyle 0 menu setdef fontcolor %Black menu Button Quit 10 10 50 25 Quit menu pushdef ; this inherits any defaults menu panel PnlRad1 10 70 100 80 menu setprop PnlRad1 color %red ; we can see where the panel borders are, because items inside it are set relative to the panel location menu setdef parent PnlRad1 ; sets all new items to have it's parent set to PnlRad1 menu radio RADingot1 10 5 80 20 #true Ingots menu radio RADboard1 10 30 80 20 #false Boards menu radio RADsaltpeter1 10 55 80 20 #false Saltpeter menu popdef ; restores previous defaults at the 'pushdef' statement above menu pushdef ; this inherits any defaults menu panel PnlRad2 115 70 100 80 menu setprop PnlRad2 color %blue ; we can see where the panel borders are, because items inside it are set relative to the panel location menu setdef parent PnlRad2 ; sets all new items to have it's parent set to PnlRad2 menu radio RADingot2 10 5 80 20 #true Ingots menu radio RADboard2 10 30 80 20 #false Boards menu radio RADsaltpeter2 10 55 80 20 #false Saltpeter menu popdef ; restores previous defaults at the 'pushdef' statement above menu text txt1 70 10 menu text txt2 70 40 menu setprop FormEquivalent visible #true returnUpdated Feb 11, 2020


Display Debug/Error Messages in a Called Library
Here is an example to create a menu inside a called library to display an error message.
This example gives a configurable option for where to place the message, which could be handled with a variable setting instead of passed into the library. I just chose to demonstrate with the passed values.

--- Code: easyuo ---; User script which calls a library example.; The passed parameters are the x and y location where to place the "error message menu" on the screen.call library_menu.txt Library_routine1 700 20wait 40call library_menu.txt Library_routine2 500 20halt
--- Code: easyuo ---; Library file that is called by the user script.; This is not an example of how to setup a library with multiple subs - look at Endless Night's examples for that.; This will set an error message on the screen which doesn't halt the processing. The user can close the form by using the "X" method.; If a button were defined, then the calling script would have to handle the button function, ; which would make an undue requirement on the caller.; This is better than "saying" something by the character running the script because it keeps the information out of the UO client.; It is also better than only a simple #result returned, because you can show more information unobtrusively to the client.set %errorx %2set %errory %3gosub %1exit sub Library_routine1 ; When an actual error is encountered, you would issue the gosub to the form routine ; This just demonstrates the functional logic gosub errorMessage An error has occurred in Library_routine1return sub Library_routine2 ; When an actual error is encountered, you would issue the gosub to the form routine ; This just demonstrates the functional logic gosub errorMessage An error has occurred in Library_routine2return sub errorMessage set %EM_message if %0 > 0  {  for %EM_index 1 %0   {   set %EM_message %EM_message , % . %EM_index   if %EM_index < %0    set %EM_message %EM_message , #spc   }  } else  set %EM_message A , #spc , generic , #spc , error , #spc , occurred. menu form formerror %errorx %errory 300 50 formerrror menu setprop formerror visible #true menu text 10 10 20 %EM_messagereturn

TrailMyx:
Awesome contribution, Gaderian!  Thanks for the input.  I've been away long enough not to realize there was this much change.  Do you think there are some legacy scripts out there that were negatively impacted by this?  I notice you talk about unsupported commands, but they seem to be obscure in nature and probably not used much.

Gaderian:
The major change is reusing element names which force menus to break. I have examples to edit above showing how to fix these. I just ran out of time last night.

If a script deleted and recreated the same name button-it no longer honors the click on the new button.
That is very common for pause/resume for scripts.

Another is delete/recreate a text widget for message display.

I have examples on how to fix each of these common issues.

I also have examples using new features to do other things that were not available with the original menu functions. I will update it as I have time soon.

Navigation

[0] Message Index

[#] Next page

Go to full version