Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
Smooth
Beginner


Joined: 05 Aug 2002
Posts: 25

PostPosted: 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?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: 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
Reply with quote
Smooth
Beginner


Joined: 05 Aug 2002
Posts: 25

PostPosted: 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?
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: 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.
Reply with quote
Smooth
Beginner


Joined: 05 Aug 2002
Posts: 25

PostPosted: 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.
Reply with quote
Anaristos
Sorcerer


Joined: 17 Jul 2007
Posts: 821
Location: California

PostPosted: 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.
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: 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
Reply with quote
Smooth
Beginner


Joined: 05 Aug 2002
Posts: 25

PostPosted: 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?
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: 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?
Reply with quote
Smooth
Beginner


Joined: 05 Aug 2002
Posts: 25

PostPosted: Sat Oct 23, 2010 9:15 pm   
 
Thanks, it works great!
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: 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.

&lt;
Code:
&lt;
_________________
Taz :)
Reply with quote
DraxDrax
Apprentice


Joined: 22 Mar 2009
Posts: 149

PostPosted: Sat Oct 23, 2010 11:02 pm   
 
&lt;

I'm going to have to write that one down. Thanks Taz!
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot 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

© 2009 Zugg Software. Hosted by Wolfpaw.net