|
Vodoc Apprentice
Joined: 11 Apr 2003 Posts: 119 Location: Sweden
|
Posted: Wed Sep 08, 2004 1:05 pm
Bug with %param(n)?? |
I have a weird problem.
I have this trigger:
Code: |
#TRIGGER {~< (%n) (%n) (%n) ~>} {#VARIABLE char_hp {%1} {_nodef} "basic|stats";#VARIABLE char_ma {%2} {_nodef} "basic|stats";#VARIABLE char_mo {%3} {_nodef} "basic|stats"} "basic|stats" {prompt} |
and this alias:
Code: |
#ALIAS emote {#SHOW {};#IF (%numparam( ) = 0) {#SHOW {My emotes:};#SHOWDB @myemotes} {#IF (%param( 1) =~ "add") {#NOOP;#SHOW Add!!} {#NOOP;#SHOW something else -%param( 1)-}}} "test" |
Let’s disable the trigger for now and just focus on the alias for now. When I type “emote” will it show information on a few emotes, like this:
Code: |
My emotes:
bow: bows deeply.
snicker: snickers. |
And when I type “emote add bla” will it show “Add!!” and “emote bla bla” will show “something else -bla-“.
The behaviour is precisely as intended this far so let’s enable the trigger. Let’s issue a command like “look” so that the prompt will come up; mud output as follows:
Code: |
< 513 438 123 > look
City Orphanage
The room you are in is very cramped but is clean very well kept. In one
corner there are several cots and toys. The faint smell of soiled diapers
permeates the air in these confines.
Exits: None.
The corpse of an orphan is lying here.
The corpse of a nursemaid is lying here.
< 513 438 123 > |
Now if I type “emote” after this happens the following:
Code: |
something else -513- |
See, the problem is that my hp for some reason acts like parameter one to the alias. However if I issue the command “emote” again will it work fine, it’s just when it’s used directly after the prompt (and thus the trigger) that things get screwed up.
So, is this a weird bug in zMUD or just something funny with my triggers/aliases?? Help is appreciated.
/Vodoc |
|
|
|
Rorso Wizard
Joined: 14 Oct 2000 Posts: 1368
|
Posted: Wed Sep 08, 2004 1:39 pm |
It seems to be a bug.
The differences with the two different executions is that in the faulty one this happens:
1. You send 'emote'.
2. The emote alias sends #show "" which adds a new line to the prompt. Therefore the trigger is called.
3. After the trigger has processed the pattern it returns.
4. The %param function returns the arguments to the trigger instead of the alias. So the parameters aren't properly restored before the trigger returns.
To solve this you might be able to rewrite the alias like this:
#SHOW {}
#IF (%null( %-1)) {
#SHOW {My emotes:}
#SHOWDB @myemotes
} {
#IF (%1 =~ "add") {
#NOOP
#SHOW Add!!
} {
#NOOP
#SHOW something else -%1-
}
}
Edit: Don't forget to report the bug to the bug tracking system. http://www.emobius.com/mantis |
|
|
|
LightBulb MASTER
Joined: 28 Nov 2000 Posts: 4817 Location: USA
|
Posted: Wed Sep 08, 2004 5:37 pm |
Just move the first #SHOW inside the #IF commands, so you check the parameters before it's sent. I also changed the operator for the second #IF to =, so it will only be true if %1 is "add", not if it's "madder".
Code: |
#ALIAS emote {#IF (%numparam( ) = 0) {#SHOW;#SHOW {My emotes:};#SHOWDB @myemotes} {#IF (%lower( %1) = "add") {#SHOW;#SHOW Add!!} {#SHOW;#SHOW something else -%1-}}} "test" |
|
|
_________________ LightBulb
Senior member
Most scripts in this forum are written for Command Line entry.
Don't even open the Settings Editor unless its use is specified or obvious. |
|
|
|
Vodoc Apprentice
Joined: 11 Apr 2003 Posts: 119 Location: Sweden
|
Posted: Wed Sep 08, 2004 6:42 pm |
Yes, just removing the first #show fixed the problem, can't imagine I didn't try that.. Buggy behavior though, I will report it to bug tracker.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Thu Sep 09, 2004 4:53 pm |
I think this would also work better if you used #ECHO instead of #SHOW. #SHOW is really intended to mimic text sent from the MUD, and after a #SHOW, your script gets interrupted so that zMUD can process this line from the MUD. If you are just displaying output from your script, the #ECHO command might work better.
But yes, I can see the basic problem that Rorso uncovered is that the %param and %numparam are not handled recursively. In other words, it gets set to the last alias or trigger that is executed. There is no "stack" of these parameters to restore. This is not an easy fix, but I'll still accept the bug report entry. But you should try to find a workaround. |
|
|
|
Vodoc Apprentice
Joined: 11 Apr 2003 Posts: 119 Location: Sweden
|
Posted: Fri Sep 10, 2004 2:23 pm |
#ECHO is just as bad as #SHOW unfortunately, as a work around do I have to make sure to use %numparam() before I send anything else to the mud. A bit cumbersome though, starting to get a pretty advanced alias where I need to use %numparam() deep into the code, well guess I will have to create a temporary variable or something in the beginning for now.
|
|
|
|
|
|