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
kjaerhus
Magician


Joined: 18 Dec 2006
Posts: 317
Location: Denmark

PostPosted: Sun Nov 14, 2010 10:13 am   

[3.32] Alarms and multiple packages, multiple windows
 
There seem to be a problem with alarms and multiple packages and multiple windows. I am trying to encapsulate certain features in different packages and use them from my default package. In this case I wanted to encapsulate some roundtime handling in it's own package and I implemented it using an alarm defined like below (I've added a few debug statements here and there to see what was was going on):

Code:
<trigger name="RoundtimeTicker" type="Alarm" priority="170" id="17">
  <pattern>*1</pattern>
  <value>
    #SAY "Tick!"
    decRoundtime
  </value>
</trigger>


Don't mind the decRoundtime alias which is not causing problems. It just decreases the roundtime variable by one. Now, this alarm is resumed whenever I receive a roundtime of x seconds and suspended when roundtime is < 1. It's resumed and suspended from aliases within the same package.

So for a roundtime of 8 seconds I would have thought I would see 8 tick messages in my main window in the session package but I only got 4. After looking through the code several times and nearly going crazy (well almost) I found that there was also 4 tick messages in a secondary window in the session package. But how was the alarm related to this window? I had another window in the session package but this didn't cause any problems. I tried adding another window and suddenly that took some tick messages too.

So bottom line is that behavior of alarms is somehow arbitrary in multi-package environments as extra windows in the session packages may or may not cause problems.
Reply with quote
kjaerhus
Magician


Joined: 18 Dec 2006
Posts: 317
Location: Denmark

PostPosted: Sun Nov 14, 2010 10:55 am   
 
Just found out that if I create a button in the same package as the alarm the button is shown for the same windows as received tick messages.
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Nov 14, 2010 4:43 pm   
 
This is not a bug, actually. Alarms don't trigger on text, so there's no way to assign scope to them unless they are already limited (ie, in a window). This means that any alarm in a module gets applied to every window that can see that alarm. Similar things happen with buttons, as you saw.

One thing you can do is to move the alarm to the main window, and then #RAISE an event. You can then make an event in the script where the alarm used to be to hold the code the alarm used to do.
_________________
EDIT: I didn't like my old signature
Reply with quote
kjaerhus
Magician


Joined: 18 Dec 2006
Posts: 317
Location: Denmark

PostPosted: Sun Nov 14, 2010 4:58 pm   
 
MattLofton wrote:
This is not a bug, actually. Alarms don't trigger on text, so there's no way to assign scope to them unless they are already limited (ie, in a window). This means that any alarm in a module gets applied to every window that can see that alarm. Similar things happen with buttons, as you saw.

One thing you can do is to move the alarm to the main window, and then #RAISE an event. You can then make an event in the script where the alarm used to be to hold the code the alarm used to do.

I am sure that you saw that it doesn't happen for all windows so at least the behaviour is not deterministic. This can not be good.

Why is it you think that the alarm should be triggered for several windows?

What happens is this: I set the alarm to ring every second until roundtime is 0. For every alarm I decrease the roundtime variable by one. Now, this you would think would result in the alarm being active for 8 seconds but in reality it will be 8 seconds divided by the number of windows. If this is done by design I'd say that the design is poor.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Sun Nov 14, 2010 8:24 pm   
 
The reason the alarm runs in several windows is because the package that the alarm is in is enabled in several windows. It is deterministic. I know that by default packages are enabled for all windows. You can control this programmatically. When I'm on my other computer, I'll post the code snippet I used to do it.
_________________
Asati di tempari!
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Sun Nov 14, 2010 8:38 pm   
 
Quote:

If this is done by design I'd say that the design is poor


The design is only poor if you can demonstrate how to do it a better way. You cannot, because you do not understand how CMud works.
_________________
EDIT: I didn't like my old signature
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Nov 15, 2010 2:32 am   
 
You can use the %packages function to set or see the packages enabled for a given window.
_________________
Asati di tempari!
Reply with quote
kjaerhus
Magician


Joined: 18 Dec 2006
Posts: 317
Location: Denmark

PostPosted: Mon Nov 15, 2010 5:15 pm   
 
Tech wrote:
The reason the alarm runs in several windows is because the package that the alarm is in is enabled in several windows. It is deterministic. I know that by default packages are enabled for all windows. You can control this programmatically. When I'm on my other computer, I'll post the code snippet I used to do it.

Ok, I've verified that the window that didn't received tick messages didn't have the package with the alarm enabled for some reason so it's deterministic allright. That's a good thing at least.

I think the problem I have with it being run from multiple windows is that if I design a package for an environment I don't know how would I determine which windows it should run for. And users who imports my package wouldn't know that something they initiate from one window would affect other windows. You see what I mean?
Reply with quote
kjaerhus
Magician


Joined: 18 Dec 2006
Posts: 317
Location: Denmark

PostPosted: Mon Nov 15, 2010 5:18 pm   
 
MattLofton wrote:
Quote:

If this is done by design I'd say that the design is poor


The design is only poor if you can demonstrate how to do it a better way. You cannot, because you do not understand how CMud works.

You're not usually that grumpy, are you? Very Happy

I expressed my concerns in the post above.
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Mon Nov 15, 2010 7:45 pm   
 
kjaerhus wrote:
I think the problem I have with it being run from multiple windows is that if I design a package for an environment I don't know how would I determine which windows it should run for. And users who imports my package wouldn't know that something they initiate from one window would affect other windows. You see what I mean?


I would see the the 'problem' in this case is in the design of the alarm. You essentially wanted a scenario where the alarm is a Singleton, because it is directly modifying the variable. You need to either control access to the variable being decremented or control the instances of the alarm. For example you can have the alarm also remove the package from all windows except the session window.

Also since as I understand round timers (they are very similar to ticks) you might consider using the built in Tick Timer
_________________
Asati di tempari!
Reply with quote
kjaerhus
Magician


Joined: 18 Dec 2006
Posts: 317
Location: Denmark

PostPosted: Mon Nov 15, 2010 8:30 pm   
 
Tech wrote:
I would see the the 'problem' in this case is in the design of the alarm. You essentially wanted a scenario where the alarm is a Singleton, because it is directly modifying the variable. You need to either control access to the variable being decremented or control the instances of the alarm. For example you can have the alarm also remove the package from all windows except the session window.

Also since as I understand round timers (they are very similar to ticks) you might consider using the built in Tick Timer

I suppose the packages function could be usable in order to avoid access to your package from any other window that the main one but I think this mechanism would be prone to errors as users may create new windows themselves which could mess up things so I am a little sceptical about this setup. I think the way it works today is a bit confusing and it certainly took me an hour or two figuring out that the alarm I thought was activated one time per second actually was activated one time per second per window. You can argue that it's logical due to the way packages work but then I am not completely sold to the way packages work yet.
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