|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Fri Sep 15, 2006 6:59 pm
Changes to expression triggers in CMUD |
I am proposing a change to Expression Triggers in CMUD, but I want to get feedback from people on this before I change it (which means I'll be posponing this until v1.07).
In zMUD, Expression Triggers are tested and executed each time *any* variable changes. For example:
Code: |
#trigger (@a > 1) {trigger fired}
a=2
b=1 |
causes the trigger to fire *twice*. It fires once when @A is set to 2, but then it fires again when @B is set to 1 (because @A is still > 1 in the trigger test).
This has always been pretty odd behavior, and is actually a bit kludgy to implement.
In CMUD we can change this. Because of the way in which scripts are compiled, CMUD has a system to determine which settings depend upon which variables. So it is possible in CMUD to only fire the trigger when the variables within the trigger pattern actually change.
In other words, the above trigger would only be tested and fire when the @A variable gets changed. Changes to other variables wouldn't effect it. In the above example, the trigger in CMUD would only fire once (when @A is set to 2). Setting @B wouldn't have any effect since the trigger doesn't use @B in the pattern.
It seems like this would be a more consistent behavior for Expression Triggers. My guess is that many people do not use Expression Triggers because of how they work strangely in zMUD. But I'd like to hear feedback from people on this. Especially if you already use Expression Triggers. Tell me how you are using Expression Triggers and whether this change would make things better or worse. |
|
|
|
bortaS Magician
Joined: 10 Oct 2000 Posts: 320 Location: Springville, UT
|
Posted: Fri Sep 15, 2006 7:35 pm |
I don't remember running into any issues with this trigger firing pattern, but I don't write too many complex scripts. I do like that this proposed behavior will put zScript in line with mainstream languages.
|
|
_________________ bortaS
~~ Crusty Klingon Programmer ~~ |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Fri Sep 15, 2006 8:45 pm |
I would love the change.
In my expression triggers in Zmud I would always test for a change I made the first time the trigger fired. IE if this is the first time it fires again don't do anything.
The double triggering always bugged me but it never managed to stop me |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
Darrant Beginner
Joined: 21 Jun 2003 Posts: 11 Location: USA
|
Posted: Fri Sep 15, 2006 9:18 pm |
That would rock. I use to use expression triggers to do multiple things for me, but if another variable was being used it would cause the expression triggers to go freak out, sounds like this would be a great fix.
|
|
_________________ Darrant
zMUD 7.21
cMUD 1.08 - Beta |
|
|
|
Vorax Apprentice
Joined: 29 Jun 2001 Posts: 198 Location: USA
|
Posted: Fri Sep 15, 2006 9:44 pm |
I would have to agree as well. This would solve some issues with expression triggers.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Sep 16, 2006 12:05 am |
Seems pretty unanimous. Implementing Expression Triggers in this way is easy in CMUD, so I'm going ahead with the change.
|
|
|
|
Caled Sorcerer
Joined: 21 Oct 2000 Posts: 821 Location: Australia
|
Posted: Sun Sep 17, 2006 4:25 am Re: Changes to expression triggers in CMUD |
Better that way for me too.
So long as:
#TRIGGER (@var=1000) {#SH Var is 1000!}
If I then type in the following three commands, the message "Var is 1000!" is currently (zmud) only displayed once
var=500
var=1000
var=1000
Please keep it that way (that is to say, that if the variable already has the value that you are attempting to set it to, then this attempt does not register as a changing value, not causing the trigger to fire.
I use expression triggers to make decisions about variables set by a prompt trigger. This is better for system speed than using #IF statements in the prompt trigger, since the expression trigger is not evaluated every line, but only when the actual variable value in question changes. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sun Sep 17, 2006 4:57 am |
Yep, that's correct. It only fires once (the first time you set var=1000)
|
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Mon Sep 18, 2006 11:02 pm |
Am I right in thinking that the new expression triggers would be more efficient, performance-wise, than the old ones? I don't know if this was a factor before - I had never looked at them, let alone used them. But it seems like the old way could be quite inefficient, performance-wise, if you had a fair number of expression triggers, and lots of setting of various variables very often.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Sep 19, 2006 5:57 am |
Oh yeah, *much* more efficient! In zMUD, everytime *any* variable changed (even if it was set to the same value), the button bar was updated, the status bar was updated, and it looped through all expression triggers and parsed them to figure out if anything needed to be fired. You can imagine how time consuming this could eventually get.
CMUD is super efficient. It knows the dependencies between various settings. So, a button is only updated when a variable that it depends upon changes. Same with a status bar, and same with expression triggers. Also, since things are compiled, testing the expression trigger doesn't require recompile/reparsing each time the variable changes. So if you use expression triggers, you will see huge benefits over zMUD. |
|
|
|
Riesz Novice
Joined: 16 May 2006 Posts: 35 Location: Plymouth, England
|
Posted: Tue Sep 19, 2006 7:51 am Re: Changes to expression triggers in CMUD |
Zugg wrote: |
My guess is that many people do not use Expression Triggers because of how they work strangely in zMUD. |
Yes, exactly that. I tried using them, but since I'm setting variables every prompt, it spammed me to death and locked up the program. They do seem quite useful for certain types of script and I would like to see that change. It also explains to me why it wasn't working how I thought it was! |
|
_________________ Elaria, Lusternia. |
|
|
|
Seb Wizard
Joined: 14 Aug 2004 Posts: 1269
|
Posted: Tue Sep 19, 2006 10:06 am |
Zugg, I just thought it might be good to confirm if you have changed this in 1.06... I know you said above that it would be for 1.07, but it seemed like from you blog you may have changed it already for 1.06...
|
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Tue Sep 19, 2006 5:02 pm |
I had similar strange experiences with expression triggers in zMUD. I tried to use them for the logic in my combat scripts for Achaea, but they fired unpredictably and made the program run very slowly because of my dozens of variables constantly firing the triggers.
My hope is that expression triggers will be useful in building complex logic and keeping things somewhat centralized or generalized at the same time. This new CMUD compiler sounds like a great advancement for the MUD scripting world. Can't wait to really see what it can do when everything's all put together in the final version.
On a semi-related note (and hopefully not too much of a tangent), will the compiler handle nested custom functions better than zMUD? I had built up lots of custom functions for my complex logic, and I found that nesting too many of them too many levels deep brought zMUD to its knees. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Tue Sep 19, 2006 6:28 pm |
Seb: Yes! Expression Triggers are in 1.06. You'll see them mentioned in the (long) version history. They should work just how you'd like them too now.
Larkin: There shouldn't be any problem with nested functions in CMUD, but give them a try and post a different thread with specific examples if something doesn't work right. I plan for more "traditional" functions in the future also. |
|
|
|
|
|