|
nigma Newbie
Joined: 30 Apr 2007 Posts: 7
|
Posted: Sun Jul 29, 2007 7:56 am
zMud to CMud Escape Key change |
In zMud I was able to hit the Escape key to halt the execution of scripts. Doing that in CMud doesn't seem to work. Is there a new key, something needs to be set up, or am I just out of luck?
|
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Jul 29, 2007 2:46 pm |
This should still work in CMud. It was implemented correctly well back in around version 1.10. It will only affect the various looping commands, which is a change from zMud. Perhaps you should post some details of the script and how it is getting hung.
|
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
nigma Newbie
Joined: 30 Apr 2007 Posts: 7
|
Posted: Sun Jul 29, 2007 5:11 pm |
what's happening is I have a series of aliases that are called to preform actions. All the aliases but one are Mud specific and don't involve CMud. One, I think is the problem. It is the loop I do, that check to see if a flag is set before continuing on with the next action. For my own limited programming skill I have not found a way around using #WAIT. It gets called in a #WHILE loop.
Code: |
equilibrium=0
#while (@equilibrium <>1) {#wait 50}
|
With a trigger that resets equilibrium to 1 on a specific message back in the mood.
While a command is executed successfully it works, but if a command fails to execute, the equilibrium variable never gets reset. I used to be able to use ESC to jump out of an ALIAS like that.
I guess ultimately, I have two issues.. the first having a better way to handle actions that have to wait on a flag. The second being, how do I clear commands stacked up by misfiring triggers or poorly working aliases.
Thanks. |
|
Last edited by nigma on Sun Jul 29, 2007 5:27 pm; edited 1 time in total |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jul 29, 2007 5:25 pm |
There are plenty of ways to handle this that don't involve the #wait command (indeed, #wait can cause lots of problems in 1.34. They're fixed in 2.0, but it could still be causing crashes when you try to close CMUD and other niceties). One possible solution might be:
#while (@equilibrium <> 1 AND @abortscripts=0) {#wait 50}
then you just set abortscripts and the loop exits. You could have an #if immediately afterwards (not in the loop because that'd cause it to be slower) that checks @abortscripts and sends #abort 1 if that's what broke the loop.
Really, it depends exactly when you want your code executed. If you have an alias that "queues up" a command to execute when you next get your equilibrium back, if you don't already have it, you might want to use a proper command queue with a string list to store the commands. It'd change your code from
#while (@equilibrium <>1 ) {#wait 50}
doSomething
to
#var StuffToDo %additem(@StuffToDo,"doSomething")
or maybe
#if (@equilibrium) {#var StuffToDo %additem(@StuffToDo,"doSomething")} {doSomething}
Then, in the trigger that sets your equilibrium back to 1, you test to see if the list has any items, and if it does, to execute them:
#if (@StuffToDo) {#exec %pop(StuffToDo)}
If you're using it for something else, you might need a different solution, but this one is good because it prevents you from setting two commands that'll take your equilibrium when you use them by accident. If that happened, you wouldn't know which was going to execute first.
PS. In version 2.0, if you just wanted to wait for the MUD to send "You have recovered equilibrium" you could use the new #waitfor command:
#waitfor "You have recovered equilibrium."
and the script will halt until it gets whatever pattern from the MUD, sort of like using the #temp command. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sun Jul 29, 2007 6:30 pm |
The way the abort from pressing ESC is failing for you is that it is cancelling the #WAIT only. Your loop never gets cancelled because a new #WAIT is issued before a second or held keypress gets registered. That particular behavior might be classed as a bug.
Now to a better way to write the script. Since there is triggerable line for receiving equilibrium you can put everything from the alias after that while into its own alias. Then use a #TEMP trigger to activate it.
Some of CMuds new features actually let you create a whole queue by this simple method. Because the permanent triggers will always have a better priority value then a new #TEMP trigger you know they will fire first and adjust variables and such. The #TEMP can be created with the stop further processing option allowing that only one such temporary trigger will fire, and they will fire in the sequence in which they were created. This creates a very simple queue system that actually has CMud doing practically all the clean up. You can further enhance this by using the ID field to ensure no duplicates. I plan on rewriting my own priority queue system to make better use of this. I believe the option word is "stop", but I can't find the trigger options document in the help.
#TEMP ID {^You have recovered equilibrium.$} {NewAliasThatDoesStuff} "" {stop} |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Sun Jul 29, 2007 7:13 pm |
The new version of CMUD would handle these things better, but I wouldn't consider it a bug (at least not a bug in CMUD) because it does exactly it was supposed to do. It's a bug in Nigma's code if anything, because it's not well written code (no offense Nigma).
Fang's suggestions are a better approach to the problem. |
|
_________________ Asati di tempari! |
|
|
|
nigma Newbie
Joined: 30 Apr 2007 Posts: 7
|
Posted: Sun Jul 29, 2007 8:24 pm |
Tech wrote: |
The new version of CMUD would handle these things better, but I wouldn't consider it a bug (at least not a bug in CMUD) because it does exactly it was supposed to do. It's a bug in Nigma's code if anything, because it's not well written code (no offense Nigma).
Fang's suggestions are a better approach to the problem. |
No offense taken, I know it is bad code. I will try playing with Fang's suggestions, it seems like a much better solution for what I wanted. |
|
|
|
|
|