|
Smooth Beginner
Joined: 05 Aug 2002 Posts: 25
|
Posted: Fri Oct 22, 2010 8:29 pm
#varfunc in a status bar? |
Hey I've got this script that was imported from zmud (not by me) and it worked fine there.
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger priority="1680">
<pattern>^You perform cureall surgery on yourself.$</pattern>
<value>#cw greenyellow
#ALARM "CureallAlarm" +10:00 {#sa Cureall ready again.}
#FUNCTION CureallTime {%concat( %eval( (%alarm( CureallAlarm)/1000)/60), ":", %mod( %eval( %alarm( CureallAlarm)/1000), 60), " Min(s)")}</value>
</trigger>
<stat name="StatBar1" priority="3530">
<value><![CDATA[<color lightblue black> W: @wimpypercent% - @wimpy hps </color><color white black> ||| </color><color green black> EXP: @exp Align: @align DR: @drugged </color><color white black> ||| </color><color yellow black> CA: @CureallTime(CureallAlarm) </color><color white black>||| </color><color cyan black>S: @SilverTime(SilverAlarm) </color><color white black>||| </color><color violet black> ARush: @ARushTime(ARushAlarm) </color><color white black>||| </color>]]></value>
</stat>
</cmud> |
It doesn't display anything in the status bar for the cureall timer like it's supposed to. Near as I can tell, #function should now be #varfunc (cmud version 2.37), but changing that doesn't fix it - it looks like when the CureallTime varfunc changes, the status bar isn't updated, even though status bars are supposed to update when a variable is changed. Does this not apply to varfuncs? |
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Fri Oct 22, 2010 10:29 pm |
#VARFUNC in CMud = #FUNCTION in ZMud.
#FUNCTION in CMud = not available in ZMud (essentially it's like an #ALIAS that returns a value to whatever called it.)
#FUNCTION in CMud requires the use of the #RETURN command, if you're planning on using the function in a statusbar or some other situation where you need the data to appear in a specific spot in the code. Basically, your code is working exactly as intended and you made a user error (ie, no #RETURN means your function didn't return any data for the statusbar to use). |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Smooth Beginner
Joined: 05 Aug 2002 Posts: 25
|
Posted: Sat Oct 23, 2010 1:15 am |
I'm aware of that. If you read what I said, I tried using #varfunc and it made no difference - the status bar still didn't update. I even tried using a #return with that #function - same result.
My question is, does a #varfunc not count as a changing variable for status bar purposes? And if so, is there another way of doing this? |
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Sat Oct 23, 2010 2:03 am |
I was going to suggest that you use the #UPDATE command, but it's only available from version 3.04 on and your first message suggested you have 2.37.
#UPDATE explicitly tells Cmud to update a status bar item or button rather than relying on Cmud's ability to update it automatically. It's a command that was apparently made just to deal with situations like this one.
Cmud Help wrote: |
UPDATE
Syntax: #UPDATE id
Update a button or status bar item, or a class containing these items. Causes a button caption or status item caption to be recalculated and displayed.
This is useful for buttons or status bar items that depend upon function calls and normally do not get updated when a dependent variable is changed. |
|
|
|
|
Smooth Beginner
Joined: 05 Aug 2002 Posts: 25
|
Posted: Sat Oct 23, 2010 4:39 am |
Thanks for the suggestion, Drax. Not getting anywhere with implementing that into the current script at the moment (I'm testing on cmud v3+ and the person who uses the script is willing to upgrade), but hopefully I can figure it out.
|
|
|
|
Anaristos Sorcerer
Joined: 17 Jul 2007 Posts: 821 Location: California
|
Posted: Sat Oct 23, 2010 4:45 am |
I would remove the #FUNCTION from the trigger and add the following function to the settings. Everything else stays the same.
Code: |
<func name="CureallTime" id="3">
<value>#RETURN ((%alarm( $alarm)/1000) / 60) + ":" + %mod( (%alarm( $alarm)/1000), 60) + " Min(s)"</value>
<arglist>$alarm</arglist>
</func>
|
|
|
_________________ Sic itur ad astra. |
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Sat Oct 23, 2010 4:51 am |
This is similar to what Anaristos suggested but includes an alarm to update the status bar once a second so that the time remaining before you can cureall again is counted down correctly. This would have happened automatically in zMud but needs to be called explicitly with the #UPDATE command in Cmud. Once the CureallAlarm has expired, the alarm keeping the status bar updated will be switched off until it's needed again.
This also formats the time remaining in the counter correctly when under 10 seconds remain. ie you see CA: 3:07 Min(s) instead of CA: 3:7 Min(s)
Code: |
<?xml version="1.0" encoding="ISO-8859-1" ?>
<cmud>
<trigger name="statbar1updater" type="Alarm" priority="270" enabled="false">
<pattern>*1</pattern>
<value>#UPDATE statbar1
#IF (%alarm( CureallAlarm) < 1) {#T- statbar1updater}</value>
</trigger>
<trigger priority="1680">
<pattern>^You perform cureall surgery on yourself.$</pattern>
<value>#cw greenyellow
#ALARM "CureallAlarm" +10:00 {#sa Cureall ready again.}
#T+ statbar1updater</value>
</trigger>
<stat name="StatBar1" priority="3530">
<value><![CDATA[<color lightblue black> W: @wimpypercent% - @wimpy hps </color><color white black> ||| </color><color green black> EXP: @exp Align: @align DR: @drugged </color><color white black> ||| </color><color yellow black> CA: @CureallTime(CureallAlarm) </color><color white black>||| </color><color cyan black>S: @SilverTime(SilverAlarm) </color><color white black>||| </color><color violet black> ARush: @ARushTime(ARushAlarm) </color><color white black>||| </color>]]></value>
</stat>
<func name="CureallTime">
<value>#RETURN %concat( (%alarm(CureallAlarm)/1000/60), ":", %if((%alarm(CureallAlarm)/1000\60) < 10, 0), (%alarm(CureallAlarm)/1000\60), " Min(s)")</value>
</func>
</cmud> |
|
|
Last edited by DraxDrax on Sat Oct 23, 2010 7:57 pm; edited 1 time in total |
|
|
|
Smooth Beginner
Joined: 05 Aug 2002 Posts: 25
|
Posted: Sat Oct 23, 2010 6:28 pm |
Thanks a lot Drax :)
CMUD's giving me an error when I try to import that though:
File: . Line: 6 Col: 29 Error: Invalid element name: "
Any idea what's wrong? |
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Sat Oct 23, 2010 8:08 pm |
NP :)
And yeah, the xml, as I posted it, contained code for the less than character in two places. That code is & lt; but without a space between the & and the l. The forums parse that code and replaced it with the less than character itself <. This is preventing the xml from working properly when you just copy/paste it from the forum.
For it to work properly, replace line six with this text (change in bold. remove the excess space)
#IF (%alarm( CureallAlarm) & lt; 1) {#T- statbar1updater}</value>
And replace line eighteen with this text, again removing the excess space:
<value>#RETURN %concat( (%alarm(CureallAlarm)/1000/60), ":", %if((%alarm(CureallAlarm)/1000\60) & lt; 10, 0), (%alarm(CureallAlarm)/1000\60), " Min(s)")</value>
Might someone know if there is a way to get that code to appear without the forum parsing it? |
|
|
|
Smooth Beginner
Joined: 05 Aug 2002 Posts: 25
|
Posted: Sat Oct 23, 2010 9:15 pm |
Thanks, it works great!
|
|
|
|
Taz GURU
Joined: 28 Sep 2000 Posts: 1395 Location: United Kingdom
|
Posted: Sat Oct 23, 2010 10:59 pm |
DraxDrax: & - ampersand # - hash 38 - thirty eight ; - semicolon will render an ampersand allowing you to put the lt; after without it getting merged, displays fine outside and inside of code sections.
<
|
|
_________________ Taz :) |
|
|
|
DraxDrax Apprentice
Joined: 22 Mar 2009 Posts: 149
|
Posted: Sat Oct 23, 2010 11:02 pm |
<
I'm going to have to write that one down. Thanks Taz! |
|
|
|
|
|