help (mzscript) Thread last updated on 2004-08-12 09:15:47

Posted by member 12025 on 2004-08-11 11:37:05

; EXAMPLE:
; !eval !varSet tmp "<<test>style>_<<test>thick>_border_<<test>_grip>_bottom"

*script bang !eval
*script exec !varSet tmpParamCount 0 ; could be off a bit
*script exec !varSet tmpFirstParams ""
*script exec !varSet tmpLeft ""
*script exec !varSet tmpRight ""
*script exec !setlistsep <

*script exec !varSet tmpNextParam "%{P}{\%{tmpParamCount}}"

*script LABEL upToVar
*script exec !varSet curParam "%{tmpNextParam}"
*script exec !varAdd tmpParamCount "1"
*script exec !varSet tmpNextParam "%{P}{\%{tmpParamCount}}"
*script exec !msgbox "%{curParam} %{tmpNextParam} %{tmpParamCount}"
*script GOTOIF ( "%{tmpNextParam}" = "" ) foundVar
*script exec !ifEq tmpParamCount "1" '|varSet tmpFirstParams "%{\1}"' else '|varSet tmpFirstParams "%{tmpFirstParams} %{curParam}"'
*script exec !msgbox %{tmpFirstParams}
*script GOTO upToVar

The rest of the script works fine. It is in sticking together the first few paramters that it gives a "parameter missing" error. Any clue at all? With the example here, the !msgboxes give:
" !varset 1"
...paramter missing error.
"!varset tmp 2"
...and then it goes on about its business, with tmpFirstParams being blank.

...if anybody else has a better way to get all but the last parameter passed, I'm all up for that, too.

edit: &lt; &gt; fixed.

Posted by member 37809 on 2004-08-11 12:19:32 link

(Did you adjust your post, replacing &lt; and &gt; symbols with &amp;lt; and &amp;gt;? That !setlistsep &lt; prompts me to ask.)

What is !eval supposed to do given those arguments?
I fail to see the meaning and purpose of the whole thing.

Also for sanity, in your !msgbox calls you could do something like
!msgbox curParam="%{curParam}" tmpNextParam="%{tmpNextParam}" tmpParamCount="%{tmpParamCount}"

Posted by member 12025 on 2004-08-11 12:51:14 link

The objective is that the bang is called and passed proper parameters. The last parameter is assumed to be a set of variables in need of expansion (but actually using %{} causes problems). It expands them, then executes the bang. Given use of !ParseEvars, and having another couple bangs in mind to add to this one, it needs to just take all but the last and convert them into a string, separated by spaces, so the end can be
*script exec %{tmpFirstParams} %{result}


!msgbox: ...er, yeah, might do that :).
...ok, now I did, and made one change, just to see what it would do, and it fixed it. I've been up all night reloading Win2k, and will now sleep, but here is the 90% done script (at least five special cases need to be dealt with, but it works for easy test cases):
;------------------------------------------------------------------------------
; One-line Exapnsion/execution
;------------------------------------------------------------------------------
; USE:
; !eval !bang(s) var vara{varb{varb}}}
; EXAMPLE:
;
; !eval !ParseEvars !varSet tmp "&lt;&lt;test&gt;style&gt;_&lt;&lt;test&gt;thick&gt;_border_&lt;&lt;test&gt;_grip&gt;_bottom"
; !eval !varSet tmp "{&lt;&lt;test&gt;style&gt;_&lt;&lt;test&gt;thick&gt;_border_&lt;&lt;test&gt;_grip&gt;_bottom}" ; extra expansion !NEED TO DO
; !eval !varSet tmp "#&lt;&lt;test&gt;style&gt;_&lt;&lt;test&gt;thick&gt;_border_&lt;&lt;test&gt;_grip&gt;_bottom#" ; enclose in %# %# !NEED TO DO

*script bang !eval

*script exec !varSet tmpParamCount 1
*script exec !varSet tmpFirstParams ""
*script exec !varSet tmpLeft ""
*script exec !varSet tmpRight ""
*script exec !setlistsep &lt;

*script exec !varSet tmpNextParam "%{P}{\%{tmpParamCount}}"

*script LABEL upToVar
*script exec !varSet curParam "%{tmpNextParam}"
*script exec !varAdd tmpParamCount "1"
*script exec !varSet tmpNextParam "%{P}{\%{tmpParamCount}}"
*script exec !msgbox "parameter: %{curParam} | next: %{tmpNextParam} | count: %{tmpParamCount}"
*script GOTOIF ( "%{tmpNextParam}" = "" ) foundVar
*script exec !ifEval ( "%{tmpFirstParams}" = "" ) '|varSet tmpFirstParams "%{\1}"' else '|varSet tmpFirstParams "%{tmpFirstParams} %{curParam}"'
*script exec !msgbox "params: %{tmpFirstParams}"
*script GOTO upToVar

*script LABEL foundVar
*script exec !varSet tmpVar "%{curParam}"
*script exec !varshow curParam

*script LABEL foundVarAgain
*script GOTOIF ( "%{tmpVar:_}" = "" ) endForVar
*script exec !varSet tmpLeft "%{tmpVar:}"
*script exec !varSet tmpRight "%{tmpVar:_}"
*script exec !msgbox "parameters: %{tmpFirstParams} | left: %{tmpLeft} | right:_ %{tmpRight}"

*script LABEL loopVarIn
*script GOTOIF ( "%{tmpRight:_}" = "" ) replaceVar
*script exec !varSet tmpLeft %{tmpLeft}&lt;%{tmpRight:}
*script exec !varSet tmpRight %{tmpRight:_}
*script GOTO loopVarIn

*script LABEL replaceVar
*script exec !setlistsep &gt;
*script exec !varSet tmpRightTwo "%{tmpRight:_}"
*script exec !varSet tmpLeftTwo "%{tmpRight:}"
*script exec !varSet tmpLeftTwo "%{P}{%{tmpLeftTwo}}"
*script exec !varSet tmpVar "%{tmpLeft}%{tmpLeftTwo}%{tmpRightTwo}"
*script exec !varSet tmpLeft ""
*script exec !varSet tmpRight ""
*script exec !setlistsep &lt;
*script GOTO foundVarAgain

*script LABEL endForVar
*script exec !msgbox "%{tmpFirstParams} %{tmpVar}"

*script ~bang

Posted by member 37809 on 2004-08-11 13:50:44 link

I'm still curious as to why you would need more than two levels of var expansions so often to make it a generic omnipotent bang.
i.e. from your other post:
!eval !varSet (tmp)BoxImageLeftEdge "(((tmp)style)_((tmp)thick)_edge_((tmp)grip)_left)"

You plan to have variables for all the possible combinations, per tmp ? And then the same for other things? I'd like to dismiss it as a bad choice in design, but maybe you're on to something powerful here.

I'm just saying this all seems like it's geared to work for the "proper parameters" you present. I think you would need to use a stack to be able to expand all possible formats of nested variables. I don't know if you would want to pursue making that in current scripting while waiting for better days, those without multiple escape code paralysis.

Here's something untested of lesser ideal anyhow:
*script bang !expand ;&lt;varnameForResult&gt; &lt;varnameToExpand&gt;
*script exec !exec !varset %{\1} "%{P}{%{\2}}" ; don't remember if extra exec necessary
*script ~bang

Then on a case-by-case basis you could do things like this:
!varset q edge
!varset r bottom
!expand s %{test}_style
!expand t %{test}_thick
!expand g %{test}_grip
!expand tmp %{s}_%{t}_%{q}_%{g}_%{r}

; or worse, if it even works:
!varset tmp {%{P}{%{test}_style}_%{P}{%{test}_thick}_%{q}_%{P}{%{test}_grip}_%{r}}
!varset tmp %%{tmp}

Sometimes I think I abuse varnames :S

Posted by member 99 on 2004-08-11 20:38:49 link

Out of curiosity, was there a problem with
*script exec !exec !varset %{tmp}BoxImageLeftEdge "%{P}{P}{%{P}{%{tmp}style}_%{P}{%{tmp}thick}_edge_%{P}{%{tmp}grip}_left}"
? Or is that just too much extra confusion? (I have had a use for things nested two deep like this as well.)

tnl: !varset does an expansion on its arguments before splitting up the line. Actually, I think every bang in mzscript does, including user-defined ones.

Posted by member 37809 on 2004-08-11 20:56:04 link

That's annoying and confusing for me to have to type and have to do more than glance at later. I insist on mangling my varnames to 'being local' out of some fanatical OCD and coupled with expansion it looks fugly enough already ;)
(I'll have to adopt camelCase and break my habits. In the old days there was voodoo legend with bang names having to be lowercase or otherwise evil would show).

I prefer splitting the line up, using the method I learned:
!varset almost "{%{inner}}"
!varset there "%%{almost}"

I should change for promises of half the number of expansions and thus significant performance increases :P

Posted by member 12025 on 2004-08-12 03:57:24 link

tnl: "You plan to have variables for all the possible combinations, per tmp ? And then the same for other things?"
No, I do not plan to. I already do, and have had for a couple months now.
vwm_grip 2
vwmStyle singlebrace
vwmthick 1

With test as "vwm", these expand out "__border__bottom", to then become
$singlebrace_1_border_2_bottom$
in the end, which is 1. This way every box can have independent settings, all from a single set of evars, and using only a few !bangs, with few special cases, to get it all done.

Rabidcow: maybe, maybe not. I'll try it, being more cafeful...
I did not have good luck getting more than one additional expansion per line. Maybe I was missing a } or something when I tried. I went through making such a script because trying to get one more expansion out of a variable than possible sets the value to true.

Posted by member 12025 on 2004-08-12 07:27:26 link

Rabidcow: trying "%{P}{P}{%{P}{%{tmp}style}_%{P}{%{tmp}thick}_edge_%{P}{%{tmp}_grip}_left}", I get an error dialog box (Litestep :: Error), reading
"Variable "%{P}{%{vwmstyle}_%{vwmthick}_edge_%{vwm_grip}_left}" not defined"
It's doing the two expansions that I can get normally w/ !varset, and that's it.

Posted by member 12025 on 2004-08-12 09:15:47 link

I have a few ideas for shortening it, but here's the working script
;------------------------------------------------------------------------------
; One-line Exapnsion/execution
;------------------------------------------------------------------------------
; USE:
; !eval !bang(s) var vara&lt;varb&lt;varb&gt;&gt;
; EXAMPLES:
;
; !eval !varSet tmp "&lt;&lt;&lt;test&gt;style&gt;_&lt;&lt;test&gt;thick&gt;_border_&lt;&lt;test&gt;_grip&gt;_bottom&gt;" ; expands to value
; !eval !varSet tmp "*&lt;&lt;test&gt;style&gt;_&lt;&lt;test&gt;thick&gt;_border_&lt;&lt;test&gt;_grip&gt;_bottom*" ; get current evar (uses xlabel)
; !eval !varSet tmp "#&lt;&lt;test&gt;style&gt;_&lt;&lt;test&gt;thick&gt;_border_&lt;&lt;test&gt;_grip&gt;_bottom#" ; enclose in %# %# for evar

*script bang !eval
*script exec !varSet tmpParamCount 1
*script exec !varSet tmpFirstParams ""
*script exec !varSet tmpLeft ""
*script exec !varSet tmpRight ""
*script exec !setlistsep &lt;

*script exec !varSet tmpNextParam "%{P}{\%{tmpParamCount}}"

*script LABEL upToVar
*script exec !varSet curParam "%{tmpNextParam}"
*script exec !varAdd tmpParamCount "1"
*script exec !varSet tmpNextParam "%{P}{\%{tmpParamCount}}"
;*script exec !msgbox "parameter: %{curParam} | next: %{tmpNextParam} | count: %{tmpParamCount}"
*script GOTOIF ( "%{tmpNextParam}" = "" ) foundVar
*script exec !ifEval ( "%{tmpFirstParams}" = "" ) '|varSet tmpFirstParams "%{\1}"' else '|varSet tmpFirstParams "%{tmpFirstParams} %{curParam}"'
;*script exec !msgbox "params: %{tmpFirstParams}"
*script GOTO upToVar

*script LABEL foundVar
*script exec !varSet tmpVar "%{curParam}"
;*script exec !varshow curParam

*script LABEL foundVarAgain
*script GOTOIF ( "%{tmpVar:_}" = "" ) endForVar
*script exec !varSet tmpLeft "%{tmpVar:}"
*script exec !varSet tmpRight "%{tmpVar:_}"
;*script exec !msgbox "parameters: %{tmpFirstParams} | left: %{tmpLeft} | right:_ %{tmpRight}"

*script LABEL loopVarIn
*script GOTOIF ( "%{tmpRight:_}" = "" ) replaceVar
*script exec !varSet tmpLeft %{tmpLeft}&lt;%{tmpRight:}
*script exec !varSet tmpRight %{tmpRight:_}
*script GOTO loopVarIn

*script LABEL replaceVar
*script exec !setlistsep &gt;
*script exec !varSet tmpRightTwo "%{tmpRight:_}"
*script exec !varSet tmpLeftTwo "%{tmpRight:}"
*script exec !varSet tmpLeftTwo "%{P}{%{tmpLeftTwo}}"
*script exec !varSet tmpVar "%{tmpLeft}%{tmpLeftTwo}%{tmpRightTwo}"
*script exec !varSet tmpLeft ""
*script exec !varSet tmpRight ""
*script exec !setlistsep &lt;
*script GOTO foundVarAgain

*script LABEL endForVar
;*script exec !varshow tmpVar
*script exec !setlistsep #
*script GOTOIF ( "%{tmpVar:_}" &lt;&gt; "" ) varIsEvar
*script exec !setlistsep *
*script GOTOIF ( "%{tmpVar:_}" &lt;&gt; "" ) varIsCurEvar
*script GOTO end

*script LABEL varIsEvar
*script exec !varset tmpVar "%{tmpVar:_}"
*script exec !varset tmpVar "%{tmpVar:}"
*script exec !varSet tmpVar "%#%{tmpVar}%#"
*script GOTO end

*script LABEL varIsCurEvar
*script exec !varset tmpVar "%{tmpVar:_}"
*script exec !varset tmpVar "%{tmpVar:}"
*script exec !ParseEvars !varSet tmpVar "%#%{tmpVar}%#"
*script GOTO end

*script LABEL end
*script exec !IfExist mzListSeparator {!setlistsep %{mzListSeparator}} else {!setlistsep :}
*script exec %{tmpFirstParams} %{tmpVar}
*script ~bang

and bangs using them, removing one more recycle for me:
*script bang !setStyle_box
*script exec !varset tmpBox %{\1} ; save from clearing of args
; one unnecessary expansion, yes, but for consistency.
*script exec !eval !varSet %{tmpBox}BoxImageLeftEdge &lt;&lt;&lt;tmpBox&gt;Style&gt;_&lt;&lt;tmpBox&gt;Thick&gt;_edge_&lt;&lt;tmpBox&gt;_grip&gt;_left&gt;
*script exec !eval !varSet %{tmpBox}BoxImageTopEdge &lt;&lt;&lt;tmpBox&gt;Style&gt;_&lt;&lt;tmpBox&gt;Thick&gt;_edge_&lt;&lt;tmpBox&gt;_grip&gt;_top&gt;
*script exec !eval !varSet %{tmpBox}BoxImageRightEdge &lt;&lt;&lt;tmpBox&gt;Style&gt;_&lt;&lt;tmpBox&gt;Thick&gt;_edge_&lt;&lt;tmpBox&gt;_grip&gt;_right&gt;
*script exec !eval !varSet %{tmpBox}BoxImageBottomEdge &lt;&lt;&lt;tmpBox&gt;Style&gt;_&lt;&lt;tmpBox&gt;Thick&gt;_edge_&lt;&lt;tmpBox&gt;_grip&gt;_bottom&gt;

*script exec !eval !varSet %{tmpBox}BorderLeft &lt;&lt;&lt;tmpBox&gt;Style&gt;_&lt;&lt;tmpBox&gt;Thick&gt;_border_&lt;&lt;tmpBox&gt;_grip&gt;_left&gt;
*script exec !eval !varSet %{tmpBox}BorderTop &lt;&lt;&lt;tmpBox&gt;Style&gt;_&lt;&lt;tmpBox&gt;Thick&gt;_border_&lt;&lt;tmpBox&gt;_grip&gt;_top&gt;
*script exec !eval !varSet %{tmpBox}BorderRight &lt;&lt;&lt;tmpBox&gt;Style&gt;_&lt;&lt;tmpBox&gt;Thick&gt;_border_&lt;&lt;tmpBox&gt;_grip&gt;_right&gt;
*script exec !eval !varSet %{tmpBox}BorderBottom &lt;&lt;&lt;tmpBox&gt;Style&gt;_&lt;&lt;tmpBox&gt;Thick&gt;_border_&lt;&lt;tmpBox&gt;_grip&gt;_bottom&gt;

*script exec !reposition_box %{tmpBox}
*script ~bang

*script bang !reposition_box ; name sans Box
*script exec !varset tmpBox %{\1}

*script exec !eval !LabelRefresh %{tmpBox}Box %{tmpBox}BoxImage "$LSImageFolder$&lt;&lt;tmpBox&gt;Style&gt;\&lt;&lt;tmpBox&gt;Color&gt;_&lt;&lt;tmpBox&gt;_grip&gt;.png"

;side-effect of using eval: additional expansion, like !varset
*script exec !eval !LabelRefresh %{tmpBox}Box %{tmpBox}BoxImageLeftEdge %{P}{%{tmpBox}BoxImageLeftEdge}
*script exec !eval !LabelRefresh %{tmpBox}Box %{tmpBox}BoxImageTopEdge %{P}{%{tmpBox}BoxImageTopEdge}
*script exec !eval !LabelRefresh %{tmpBox}Box %{tmpBox}BoxImageRightEdge %{P}{%{tmpBox}BoxImageRightEdge}
*script exec !eval !LabelRefresh %{tmpBox}Box %{tmpBox}BoxImageBottomEdge %{P}{%{tmpBox}BoxImageBottomEdge}

*script exec !eval !%{tmpBox}Move %{P}{%{tmpBox}BorderLeft} %{P}{%{tmpBox}BorderTop}

; wish I could do more vars in !eval, but it was tough enough to work as is.
*script exec !eval !varSet %{tmpBox}BoxWidth #&lt;&lt;tmpBox&gt;BorderLeft&gt;+&lt;&lt;tmpBox&gt;BorderRight&gt;+&lt;&lt;tmpBox&gt;Width&gt;#
*script exec !eval !varSet %{tmpBox}BoxHeight #&lt;&lt;tmpBox&gt;BorderBottom&gt;+&lt;&lt;tmpBox&gt;BorderTop&gt;+&lt;&lt;tmpBox&gt;Height&gt;#
; note: for boxes with multiple hooked things, the resizing scripts for them individually will create the width and height.

*script exec !varSet tmpBoxW %{P}{%{tmpBox}BoxWidth}
*script exec !varSet tmpBoxH %{P}{%{tmpBox}BoxHeight}
*script exec !LabelResize %{tmpBox}Box %{tmpBoxW} %{tmpBoxH}

*script ~bang

*script bang !setGrip
*script exec !varSet %{\1}_grip %{\2}
*script exec !setStyle %{style} %{\1}
*script ~bang

*script bang !trayMove ; more to come for others
*script exec !VtrayMove %{\1} %{\2}
*script ~bang