|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Tue Jul 03, 2007 9:46 pm
local variable question |
Code: |
#ALIAS alias_maker {
$temp0 = %concat(%1, "_defense_issued")
$temp1 = %concat("has_", %1)
$temp2 = %concat(%1, "_defense_enabled")
$temp3 = %concat("%if ~(~@", $temp1, " AND ~@", $temp0, " = 0,1,0~)")
$temp4 = %concat(%1, "_rename")
$temp5 = %concat(%1, "_defense")
$temp6 = %concat("#IF ~(~@response_enabled AND ~@", $temp2,"~(~)~) ~{issued_set ", $temp5, ";requested_reset ", $temp5, ";#ECHO ~{", %1, "};#SEND ~{", %1, "};disable_all}")
$temp7 = %concat($temp5, "=0;requested_set ", $temp5)
#VARIABLE $temp0 {0} {0}
#VARIABLE $temp1 {0}
#VARIABLE $temp5 {0} {0}
#FUNCTION $temp2 {$temp3}
#ALIAS $temp4 {$temp7}
#ALIAS $temp5 {$temp6}
#SAY %concat("A NEW ALIAS ", %1, "_rename has been created")
} |
this is supposed to create aliases that work within the constraits of my system...
USAGE: "alias_maker word_that_gets_sent_to_the_mud"
EXAMPLE: alias_maker bw
If the character has the skill bw then in a character setup file they manually set the #VARIABLE has_bw to 1.
This should create an alias called bw_rename that I can rename to bw if I like, and then when I call bw it sends the text "when the system is ready" i.e. enabled. (The "%1_defense" aliases are called inside the main trigger loop, which is not shown.)
PROBLEM:
ok with that being said... all it seems to create is an alias called 4, and another alias called 5. The contents of $temp4 are in 4, and the contents of $temp5 are in 5. Nothing else seems to be produced. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Jul 03, 2007 10:40 pm |
You need to explicitly expand local variables within alias and variable names. It's obvious why when you consider the #var command, since local variables are variables as well. The same applies to the #fu and #alias commands. This is working for me (just the changed lines included):
#VARIABLE %eval($temp0) {0} {0}
#VARIABLE %eval($temp1) {0}
#VARIABLE %eval($temp5) {0} {0}
#ALIAS %eval($temp4) {$temp7}
#ALIAS %eval($temp5) {$temp6}
EDIT1: The only problem is the #fu command, which doesn't seem to be expanding local variables in its second parameter properly. I tried using the same thing with #fu but the variable's contents was always blank, and %eval($temp3) didn't work either. You can get the same effect with a simple #var command, though - just change the #fu line to
#var %eval($temp2) {$temp3}
and you should be good.
EDIT2: I just noticed you have a typo in the definition of $temp3 that will break the script - there's a space between "%if" and the opening bracket of its arguments. That line should read:
$temp3 = %concat("%if~(~@", $temp1, " AND ~@", $temp0, " = 0,1,0~)") |
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Tue Jul 03, 2007 10:40 pm |
EDIT: the contents of #ALIAS 4 is $temp7's stuff, and the contents of #ALAIS 5 is $temp6's stuff, sorry about the error.
|
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Tue Jul 03, 2007 10:41 pm |
thanks I'll give that a try.
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Tue Jul 03, 2007 10:47 pm |
I just updated my post with some more info. What I said before might not apply, I don't remember what I changed.
|
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Tue Jul 03, 2007 10:49 pm |
It works, that's interesting the difference between declaring the #TRIGGER using $temp and that of var/fun.
|
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Tue Jul 03, 2007 10:50 pm |
oh i didn't look at the fun yet, I'll check that
|
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Tue Jul 03, 2007 10:55 pm |
and the #FU line is blank for me too, is that a bug? (I'll be using your suggestion to use #VAR)
|
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Jul 04, 2007 12:50 am |
The only part of this that might be a bug is the way #fu is ignoring local variables in its second argument. It probably won't be fixed now anyway since the current function system's going to be totally replaced in the next version. The first argument thing is probably because the syntaxes support local variable declarations as part of the first argument - "#alias test($param) {#say $param}" for example. The same is true of #event, #var, whatever. It could also be to prevent ambiguity when using the #var command, since you could mean to set the value of the local variable, or to set the value of the variable whose name is the value of the local variable.
|
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Wed Jul 04, 2007 1:00 am |
Oohhhhhh your comment reminds me:
any chance you'd also know how to add something like:
Code: |
#ALIAS %eval($temp4)($option) {$temp6} |
// <--- this fails btw.
so that the alias could refer to $option internally, but have the temp variables $temp4 and $temp6 expanded? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Jul 04, 2007 1:17 am |
This is a bit of a knotty problem, and perhaps something that needs improving. Could just be that I haven't stumbled on the solution, though. The problem looks to be, for what seems like the millionth time this week, implicit concatenation, or perhaps mistyping of the ($option) string. Either way, it looks like this should work:
#alias %concat($temp4,"(",$option,")") {$temp6}
but it doesn't. It creates an alias with the name whatever($whatever) and doesn't expand the parameters properly. |
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Wed Jul 04, 2007 1:52 am |
another thing that would seem problematic would be if the temp variable $option were already defined... The $ on the front end would cause all sorts of strange behavior.
It would almost be an idea that #alias name(param) {#SAY $param} be the syntax instead of #ALIAS name($param) {#SAY $param}
just my 2 cents.
It would be interesting to see a tutorial on these topics. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Jul 04, 2007 2:27 am |
I thought you actually meant $option to be a local variable of whatever was firing the trigger. If the %concat worked, you could just change it to "%concat($temp4,"($option)"" - but that doesn't work, so poo.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Jul 04, 2007 3:36 am |
The syntax for the name($param) isn't going to change anytime soon, sorry. But I think you guys are missing an obvious work-around. Whenever you are trying to create stuff indirectly like this, you should always think about using the #EXEC command:
#EXEC "#ALIAS "+$temp4+"($option) {"+$temp6+"}"
In other words, instead of trying to kludge it and just use a variable for the name of the alias, just construct the entire #ALIAS command itself, then #EXEC it. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Jul 04, 2007 11:31 am |
Now I feel silly. Thanks, Zugg! :D
|
|
|
|
|
|