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
Dakina
Novice


Joined: 22 Apr 2011
Posts: 36
Location: Colorado

PostPosted: Wed Oct 12, 2011 1:24 am   

Help with #alarm command
 
Hey Guys,

So Im trying to make a alarm that works seperate from the tic timer.

I want a countdown of 30 mins from when I "control a spirit"

The exact text to match is: The spirit of a kender citizen fades into existence as you bind it to this world
With "the spirit of a kender citizen" changing depending on the mob Im controling. "
I can control muiltiple spirits at once so Ideally I would like the alarm to output (or even better, make a guage)
that would say something like "25 mins remaining on "spirit of a kender citizen"
"20 mins remaining on "spirit of a yellow dragon"

and then clear when 30 mins is up and stop fireing. (after 30 mins I loose control of a spirit).
I also want to the alarm to clear at "the spirit off whatever stops following you"


So far what I tried to use is:

into existence as you bind it to this world
#Alarm "spirit" {-30:00} {#echo Spirits Exausted}
#Alarm {+10} {#show id:%alarm{spirit} Pattern:%alarm("-30:00")}

I got a message saying that "the alarm fired but did not compile"

Im not sure I really understand how to code a alarm right.

Anyoen able to help out?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Oct 12, 2011 2:57 am   
 
It didn't compile because you're trying to use {} instead of () for the first %alarm.

You will find, eventually, that having lots of alarms is going to be quite laggy and redundant, so you might want to look into building yourself a centralized timing script that raises events. Each script would then just need to maintain a variable and the event.
_________________
EDIT: I didn't like my old signature
Reply with quote
Dakina
Novice


Joined: 22 Apr 2011
Posts: 36
Location: Colorado

PostPosted: Wed Oct 12, 2011 4:49 am   Help with #alarm command
 
so I tried replaceing both {} with (), both, one, the other, no luck
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Oct 12, 2011 12:09 pm   
 
Matt said the problem was in the first %alarm. %alarm{spirit} should be %alarm(spirit)
Reply with quote
Dakina
Novice


Joined: 22 Apr 2011
Posts: 36
Location: Colorado

PostPosted: Wed Oct 12, 2011 2:58 pm   
 
I Gotcha now, thats because it was already inside {} so you have to move to the next level, Gotcha, sorry been over a decade since I programmed. Thanks Rahab
Reply with quote
ins0mnia
Novice


Joined: 23 Jan 2011
Posts: 42
Location: United States

PostPosted: Wed Oct 12, 2011 4:00 pm   
 
It's because %alarm is a function and spirit is the parameter.

Matt: Could you provide an example of the timing script? How would you refactor your alarms, one alarm that fires every minute? Use %secs?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Oct 12, 2011 7:07 pm   
 
Code:

<trigger type="Alarm" priority="2820" id="1">
  <pattern>*1</pattern>
  <value>//check system time and raise appropriate events
$time = ((%time("h") * 3600) + (%time("n") * 60) + %time("s"))
#raise onSecond
#if (%mod($time,60) = 0) {#raise onMinute}
#if (%mod($time,3600) = 0) {#raise onHour}
//check connected/disconnected state and raise appropriate events
#if (@//CommonFuncs/statusbarplus/ctime/connected = "C") {
  #raise onSecondConnected
  #if (%mod(@//CommonFuncs/statusbarplus/ctime/time,60) = 0) {#raise onMinuteConnected}
  #if (%mod(@//CommonFuncs/statusbarplus/ctime/time,3600) = 0) {#raise onHourConnected}
  #if (%mod(@//CommonFuncs/statusbarplus/ctime/time,86400) = 0) {#raise onDayConnected}
} {
  #raise onSecondDisconnected
  #if (%mod(@//CommonFuncs/statusbarplus/ctime/time,60) = 0) {#raise onMinuteDisconnected}
  #if (%mod(@//CommonFuncs/statusbarplus/ctime/time,3600) = 0) {#raise onHourDisconnected}
  #if (%mod(@//CommonFuncs/statusbarplus/ctime/time,86400) = 0) {#raise onDayDisconnected}
}
</value>
</trigger>


That's my timer script, though it does reference the ctimer part of my statusbarplus script (recreation of the statusbar using nothing but buttons, just so I could add collapsible button panels to it) so I can provide the differentiation between onSecond while connected, disconnected, or either/or without every script having to check for that.

I also have a second alarm that fires on midnight that raises the onDay event, though I suppose I could consolidate that.
_________________
EDIT: I didn't like my old signature
Reply with quote
Dakina
Novice


Joined: 22 Apr 2011
Posts: 36
Location: Colorado

PostPosted: Wed Oct 12, 2011 11:32 pm   Alarm Help
 
Ok, so apparently I still dont know what Im doing.

My alarm never does anything I can see.

Here's the exact script:
#cw Aqua
#Alarm "spirit" {-30:00} {#echo Spirits Exausted}
#Alarm {+10} {#show id:%alarm(spirit) Pattern:%alarm("-30:00")}


What I was trying to do is every 10 mins get a update on how long I have left on my spirits
Ideally I would actually like to change that to a countdown every minute for 30 minutes,
Even better would be if I had a gauge that counts down from 30 mins, showing mins and seconds, for each spirit I control (each spirit has a unique name, ex: The spirit of the Ogre shaman, The spirit of the Guardian of the Tower, The spirit of a Ogre scout)
Could anyone wright this script for me? Either for just something that locally echo's the time left on the spirit every minute, or even better, if it can be done, as a guage? And then break down what does what so I can get a better idea of how this work so I can make my own timers for other things? Such as a alarm that reminds me every 30 mins how long Ive been playing and to check with the wife to see if she needs anything and I dont take wife agro.
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Thu Oct 13, 2011 4:23 am   
 
This sounds similar to a script I use, where I have a large group of abilities that each have their own durations, and only a few can be active at one time. I have a pair of functions that convert the computer's clock time from minutes and seconds to the number of milliseconds since the month started (This script has the limitation that it cannot span months. If a timer is running when it strikes midnight on Halloween, it will break.)
Code:
#VARFUNC timecode {%eval(%time(d)*86400000+%time(h)*3600000+%time(n)*60000+%time(s)*1000+%time(z)}
#FUNCTION timedecode {#RETURN %if(%1<0,"-")%if(%int(%mod(%abs(%1),36000000)/60000)<10," ")%int(%mod(%abs(%1),36000000)/60000):%if(%int(%mod(%abs(%1),60000)/1000)<10,0)%int(%mod(%abs(%1),60000)/1000)}

Use @timecode anywhere you want to use the current time, use arithmetic to calculate difference in milliseconds for your timers. For example:
Code:
#TR 30minuteTimer {The 30 minute timer begins.} {timerEnd=@timecode+30*60*1000}
#GAUGE timerGauge {"Time %if(@timerEnd>@timecode,Left: @timedecode(@timerEnd-@timecode),Expired)%if(@corePulse,,)"} {@timerEnd-@timecode} {1800000}

Recall from algebra class that 30 min * 60 sec/min * 1000 millisec/sec = 1800000 milliseconds.

The gauge itself is a pain in the ass to set up from the command line, so once it's created, use the Settings Editor to reposition, resize, and select colors. You can then use #T+/- ButtonName in scripts to show/hide the buttons as needed.

At this point, you might be wondering, "WTF is %if(@corePulse,,)?" Status bars and buttons will update when variables referenced in them change. The variable that this gauge relies on, @timecode, is an indirect variable so the button doesn't know when it changes. Include this tidbit:
Code:
#VAR corePulse 0
#ALARM corePulse {1} {#ADD corePulse 1}

Every time this alarm fires, the value of @corePulse changes, and the button's %if statement checks the new value of @corePulse, sees it's true, and does nothing. But the button's whole caption was parsed to do that nothing, and the @timecode catches the current time and updates the button. The value of @corePulse is irrelevant - it need only change. All time calculations will be relative to the computer's clock (via the %time function within the @timecode variable function), so the interval of the alarm is irrelevant (this sample code is set to update every one second, but you could have it update every 60 seconds or .5 seconds or whatever you want) and timers are unaffected by CPU slowdown or network lag.

And finally:
Code:
#ALARM notthedoghouseagain {-30:00} {#ECHO <font chiller 48><color red> Check for Wife Agro!</color></font>}


I hope this is enough of a primer for you to create exactly the types of timers you want for a variety of uses.


@Matt: I don't understand how your script acts as a timer. What are the events you're calling? What's the code for onMinute or onHour?
_________________
.geniusclown

Last edited by geniusclown on Thu Oct 13, 2011 4:41 am; edited 2 times in total
Reply with quote
Dakina
Novice


Joined: 22 Apr 2011
Posts: 36
Location: Colorado

PostPosted: Thu Oct 13, 2011 4:39 am   
 
So do you do that to save on processor work or something? Or is it impossible to make a alarm w/o having it reference the actual clock? I just wanta simple countdown from 30 mins to 0 triggered on binding a spirit :-P I thought this was what alarms where designed to do basicle.
Reply with quote
geniusclown
Magician


Joined: 23 Apr 2003
Posts: 358
Location: USA

PostPosted: Thu Oct 13, 2011 4:45 am   
 
If you want to just count down 30 minutes, yeah an #ALARM is appropriate. But all it will do is fire when time's up - you can't track how much time is remaining. The code I outlined above allows a gauge to keep track of how much time remains or has passed.
_________________
.geniusclown
Reply with quote
Dakina
Novice


Joined: 22 Apr 2011
Posts: 36
Location: Colorado

PostPosted: Sat Oct 15, 2011 7:53 pm   
 
Out of curiosity, I remember way back when (atleast I think it was zmud) when zmud was able to make muiltiple tic timers. Any particular reason you cant do this in CMUD anymore?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sat Oct 15, 2011 8:37 pm   
 
Zmud was never able to make multiple tick timers either.
_________________
EDIT: I didn't like my old signature
Reply with quote
ins0mnia
Novice


Joined: 23 Jan 2011
Posts: 42
Location: United States

PostPosted: Sun Oct 16, 2011 9:32 am   
 
Here's what I came up with, hoping you know how to use XML to add things.

Code:
<trigger priority="30" id="3">
  <pattern>^The spirit of (*) fades into existence as you bind it to this world$</pattern>
  <value>#T+ spirit
#ADDKEY Spirits %1 %secs
#SH %ansi(cyan,hi)Spirit of %1 expires in 30 min.</value>
</trigger>

<trigger name="spirit" type="Alarm" priority="10" enabled="false" id="1">
  <pattern>*10:00</pattern>
  <value>#LOOPDB @Spirits {
  $time = 1800000 - (%secs - %val)
  #IF ($time > 0) {
    #SH %ansi(cyan,hi)Spirit of %key expires in %eval($time/60000)min %eval(%mod($time,60000)/1000)sec.
  } {//end if
    //#SH %ansi(cyan,hi)Spirit of %expand(%key) expired.
    #DELKEY Spirits %key
    #IF (@Spirits = "") {#SH %ansi(cyan,hi)-All Spirits Exhausted-;#T- spirit}
  }//end if-else
}//end loopdb
</value>
</trigger>

<trigger priority="50" id="5">
  <pattern>spirit of (*) stops following you</pattern>
  <value>#DELKEY Spirits %key
#IF (@Spirits = "") {#SH %ansi(cyan,hi)-All Spirits Exhausted-;#T- spirit}</value>
</trigger>

It's all hard set for 30 minutes so hopefully that's accurate.

First trigger adds the spirit to a variable with the current %secs time, this will support more than one spirit like you asked.

Second trigger is an alarm for every :10 on your computer clock to check remaining times. I commented out an 'expired' message instead of having a trigger for it at the exact time since your mud should manage that anyway.

Third trigger is the 'stops following', straight-forward enough.

@Matt: Thanks, that's helpful. Pretty clear how it would help in this case, just use an onMinute event (or make an onTenMinute fire) etc etc. Pretty cool.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Oct 16, 2011 7:20 pm   
 
Quote:

I don't understand how your script acts as a timer. What are the events you're calling? What's the code for onMinute or onHour?


the events I'm calling are:

onSecond
onSecondConnected
onSecondDisconnected
onMinute
onMinuteConnected
onMinuteDisconnected
onHour
onHourConnected
onHourDisconnected
onDay
onDayConnected
onDayDisconnected

These events are NOT part of this timer script, instead being defined in whatever script needed a timer. I COULD make more arbitrary events that fire off after X seconds/minutes/hours, but in my case I decided these were unnecessary.
_________________
EDIT: I didn't like my old signature
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Mon Oct 17, 2011 12:39 am   
 
In essence, "#RAISE eventname" means "if there is an event named eventname, execute it." An event is somewhat like an alias, except that it runs in its own thread and you can have more than one with the same name. You could have a dozen events named onMinute, and when you execute "#RAISE onMinute" all of those events will run (as long as they are enabled). Each of those events can be enabled or disabled independently. If there are no enabled events with that name, nothing happens. This allows you to create modular code like Matt's. He could write that code before he ever decided that he needed something to run on the hour, or on the minute, etc. And whenever he comes up with something new he wants to run on the timer, he just creates a new event with the appropriate name.
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