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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Keltec
Newbie


Joined: 09 May 2016
Posts: 6

PostPosted: Sun May 29, 2016 6:58 am   

Alarm issues
 
I want to use a variable to name an alarm. I cannot get it to work without super long drawn out IF commands, which is not what I want to do.

Such as

#ALARM "@groupmember1" +5 {#say working}
which does not expand my variable.

If I try ~ as in
#ALARM ~"@groupmember1" +5 {#say working}
It expands my variable, but then it creates a new class for some reason. Then creates no alarm.

Basically I have a list of up to 30 names that change every time I group. I wish to maintain timers for them based upon their names. Seems only way I can accomplish this is by assigning all group members to their own variable that does not change(say groupmember1 thru groupmember30). Then use 30 IF commands to cross check name to the variable, then create a specific NAMED alarm. Which is a lot of lines of code for something so simple to be created.

A method to name an Alarm with a variable, would alleviate a lot of my headache. Or if you can think of a better method to shorten such code, I am all for trying. Done banged my head on the wall enough trying to find a better method. Ideally a database would work best, since I plan to incorporate over a dozen timers for each GroupMember. But I havent had the best of luck with zmud database.

My current IF commands look like this, except with 30 of them. It triggers off an alias to start.

#IF %ismember( @STATUSTEMPNAME, @G3) {
#VAR GV3 -V
#VAR GTEMP3 @vittimegroup
#ALARM "G3T" +@GTEMP3 {
#say -== @G3 Vit Out ==-
#capture HealthMonitor
#ADDITEM VTLISTGROUPTEMPSPAM @G3
#VAR GV3 {}
}
} {}
#IF %ismember( @STATUSTEMPNAME, @G4) {
#VAR GV4 -V
#VAR GTEMP4 @vittimegroup
#ALARM "G4T" +@GTEMP4 {
#say -== @G4 Vit Out ==-
#capture HealthMonitor
#ADDITEM VTLISTGROUPTEMPSPAM @G4
#VAR GV4 {}
}
} {}
#IF %ismember( @STATUSTEMPNAME, @G5) {
#VAR GV5 -V
#VAR GTEMP5 @vittimegroup
#ALARM "G5T" +@GTEMP5 {
#say -== @G5 Vit Out ==-
#capture HealthMonitor
#ADDITEM VTLISTGROUPTEMPSPAM @G5
#VAR GV5 {}
}
} {}

Any method to cross check entire 30 variables with 1 line of code, would be a godsend as well. Or simply being able to name an alarm with a variable, so I do not create any duplicates for same group member. Or a better way to approach this would be appreciated. I am using Zmud 7.21. Thank you.
Reply with quote
shalimar
GURU


Joined: 04 Aug 2002
Posts: 4689
Location: Pensacola, FL, USA

PostPosted: Sun May 29, 2016 2:11 pm   
 
The issue is that anything inside quote marks is interpreted as a literal string.
You might be able to get away with it if you use %concat to build up your #ALARM line in a #VARIABLE of its own, and then #EXECUTE that.
But even then the quote marks might be a holdup.
_________________
Discord: Shalimarwildcat
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun May 29, 2016 6:02 pm   
 
The best method is to use a single, while connected, alarm.
#ALARM "GroupTimer" {-1} {#LOOPDB @GroupNames {#IF (%val>=%ctime) {#FORALL %db(@GroupActions,%concat(%key,%val)) {#EXEC {%i}}}}}

In the script section for the alarm you loop through a record variable for group names and when to act. You use a second record variable with keys like 'name12345' (name and when to do it) and values of a list of all things to perform at that time.
Adding actions becomes a matter of checking the current time and determining when to take the action, putting the action in a list with any current actions, and putting it all together in the variables
ActionTime=%eval(%ctime + @GTemp3)
#ADDKEY GroupNames {@StatusTempName} {@ActionTime}
ActionTime=%concat(@StatusTempName,@ActionTime)
#ADDKEY GroupActions {@ActionTime} {%additem("command to do whatever",%db(@GroupActions,@ActionTime))}
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Keltec
Newbie


Joined: 09 May 2016
Posts: 6

PostPosted: Mon May 30, 2016 8:04 am   
 
Vijilante wrote:
The best method is to use a single, while connected, alarm.
#ALARM "GroupTimer" {-1} {#LOOPDB @GroupNames {#IF (%val>=%ctime) {#FORALL %db(@GroupActions,%concat(%key,%val)) {#EXEC {%i}}}}}

In the script section for the alarm you loop through a record variable for group names and when to act. You use a second record variable with keys like 'name12345' (name and when to do it) and values of a list of all things to perform at that time.
Adding actions becomes a matter of checking the current time and determining when to take the action, putting the action in a list with any current actions, and putting it all together in the variables
ActionTime=%eval(%ctime + @GTemp3)
#ADDKEY GroupNames {@StatusTempName} {@ActionTime}
ActionTime=%concat(@StatusTempName,@ActionTime)
#ADDKEY GroupActions {@ActionTime} {%additem("command to do whatever",%db(@GroupActions,@ActionTime))}


Thanks. This seems like where I'd like to go with it.

So I wrote it out like this

#CLASS {TESTINGnewtimer}
#TRIGGER {Status of (&%wSTATUSTEMPNAME)} {
ActionTime=%eval( %ctime + @vittimegroup)
#ADDKEY GroupNames {@StatusTempName} {@ActionTime}
ActionTime=%concat( @StatusTempName, @ActionTime)
#ADDKEY GroupActions {@ActionTime} {%additem( "#say Working!", %db( @GroupActions, @ActionTime))}
#ALARM "GroupTimer" {-1} {#LOOPDB @GroupNames {#IF (%val>=%ctime) {#FORALL %db( @GroupActions, %concat( %key, %val)) {#EXEC {%i}}}}}
}
#CLASS 0

To understand it. I take it the alarm is supposed to execute every second, in order to cross check boot time, which is recorded to a DB variable. But it shouldn't fire unless the @actiontime is ">=" to %ctime. But instead it just keeps firing the "#say Working" every second. Then I'm not sure how %val represents @actiontime or what it does exactly.

Then next problem I am having is the values stay after it supposedly matches timer, instead of deleting. Which if the IF command was working, I wouldn't see that info anyway. Then feel its better just to clear that once per group, when I assign the group names. This would hold up to 30 names and multiple timers for each name of my group, the names and timers will change with each spell and name. I update that separately, thats why I changed the
ActionTime=%eval(%ctime + @GTemp3)

to

ActionTime=%eval( %ctime + @vittimegroup)

Which is my core vit time, that I preset in a variable.

Some help to better understand this, so I can make it work for myself. Would be greatly appreciated, thank you.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Mon May 30, 2016 5:49 pm   
 
First the #ALARM is a trigger unto itself. It should be created by now, remove the line to create it from your #TRIGGER.

Second my mistake on the logic, "#IF (%val>=%ctime)" should be "#IF (%val<=%ctime)". You understood what it is supposed to be doing correctly. Click on the links, in this post and my first post, for each function and command to read the help on them to better understand how it works.

Third, yep, I forgot to put in a #DELKEY or 2. Taken care of in the rewrite below.

Fourth, change whatever you need to, I was trying to guess what information you had where and probably guessed wrong on bunches of things. The script is designed to associate a name and time in GroupNames, it associates that name+time with a list of actions in GroupActions.

It sounds like you need to associate a list of times with a name. Adding a layer to do that using %additem, %item, and #DELNITEM is not hard. Keeping the list of times sorted saves you from checking all of them every second, for that use the %sort function. In order for it to sort properly you will want to pad the time value with 0's, that is done with %concat and %rightback. The %dups function eliminates any duplicates from the list, you can achieve the same by working with another temporary variable and #ADDITEM. The changes in the trigger would look something like:
ActionTime=%rightback(%concat("000000000",%eval(%ctime+@vittimegroup)),9)
#ADDKEY GroupNames {@StatusTempName} {%sort(%dups(%additem(@ActionTime,%db(@GroupNames,@StatusTempName))))}

and changing the alarm:
Code:
#ALARM "GroupTimer" {-1} {
 #LOOPDB @GroupNames {
  ActionTime=%item(%val,1)
  #IF (@ActionTime>=%ctime) {
   #FORALL %db( @GroupActions, %concat( %key, @ActionTimel)) {#EXEC {%i}}
   #DELKEY GroupActions {%concat( %key, @ActionTime)}
   ActionTime=%val
   #DELNITEM ActionTime 1
   #IF (@ActionTime) {
    #ADDKEY GroupNames {%key} {@ActionTime}
   } {
    #DELKEY GroupNames {%key}
   }
  }
 }
}
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD 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