|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Fri Jul 20, 2007 2:09 am
help? |
@temp = "#VARIABLE bw_defense_enabled ~{%if~(~@has_bw AND ~@bw_defense_issued = 0,1,0~)}"
#EXEC {@temp}
yields:
#VARIABLE bw_defense_enabled {0}
How do I get around this?
(same results occur with local variable $temp instead of @temp when called from inside an alias) |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Fri Jul 20, 2007 4:23 am |
0 is one of the possible values of bw_defense_enabled. If I create has_bw and bw_defense_issued and give them proper values, it works fine. If it's not working for you, it's possible that it's a scoping issue.
What I don't understand, though, is why you need to build the #var command in this way. There's probably a better way to do it. |
|
|
|
gmueller Apprentice
Joined: 06 Apr 2004 Posts: 173
|
Posted: Fri Jul 20, 2007 5:03 am |
I need the value to be %if(@has_bw AND @bw_defense_issued = 0,1,0)
|
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sun Jul 22, 2007 9:00 pm |
gmueller wrote: |
I need the value to be %if(@has_bw AND @bw_defense_issued = 0,1,0) |
In other words you want "bw_defense_enabled" to be a function with the value of %if(@has_bw AND @bw_defense_issued = 0,1,0).
If @temp = @bw_defense_enabled, then the value will always be either 0 or 1.
I'm not really sure why you would try and execute 1 or 0, or for that matter what exactly you are trying to do? Maybe explain a little better? |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jul 22, 2007 9:14 pm |
@temp != @bw_defense_enabled, it's a string that's going to be executed to create the variable bw_defense_enabled through the #exec command. It'd help if I knew how it was going to be used because there's almost certainly a better way to do it. I assume the example above's deliberately contrived.
temp = "#FUNCTION bw_defense_enabled ~{%if~(~@has_bw AND ~@bw_defense_issued = 0,1,0~)}"
#EXEC {@temp}
is working. Note that you do not need the @ when you're assigning the variable. You could also use a local variable instead of a "real" one. You don't need to quote all the special characters in the string either - ~ and " are the only special characters inside a string.
EDIT: There might be a bug here, though, since
temp = "#var bw_defense_enabled ~"%if(@has_bw AND @bw_defense_issued = 0,1,0)~""
#EXEC {@temp}
isn't working. |
|
|
|
oldguy2 Wizard
Joined: 17 Jun 2006 Posts: 1201
|
Posted: Sun Jul 22, 2007 9:17 pm |
Fang Xianfu wrote: |
@temp != @bw_defense_enabled, it's a string that's going to be executed to create the variable bw_defense_enabled through the #exec command. It'd help if I knew how it was going to be used because there's almost certainly a better way to do it. I assume the example above's deliberately contrived.
temp = "#FUNCTION bw_defense_enabled ~{%if~(~@has_bw AND ~@bw_defense_issued = 0,1,0~)}"
#EXEC {@temp}
is working. Note that you do not need the @ when you're assigning the variable. You could also use a local variable instead of a "real" one. You don't need to quote all the special characters in the string either - ~ and " are the only special characters inside a string. |
Ahhhhhh I thought he was just putting the quotes and stuff in there for posting on here. :-) I still don't even see why or how this would be necessary anyway. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Jul 23, 2007 5:02 pm |
OK, this is really getting messing, so it's time for me to chime in.
First, I have no idea why you are trying to do something this way. I think you should tell us what problem you are trying to solve in the first place. Whenever you start using #EXEC, you should usually be asking yourself if there is a better way, because #EXEC should be the last resort (it's the slowest way to do anything).
But back to your original post:
1) You should not be using the syntax: @temp = value. You don't put the @ character unless you are *expanding* the value of a variable.
2) There are some issues using ~" within quotes. In v2.0 I have fixed it so that you can just use double quotes "" to specify a single quote.
3) If you are trying to assign a function to vw_defense_enabled, then you should be using #FUNCTION (called #VARFUNC in v2.0) and not #VARIABLE.
So, I think your script should just be this:
Code: |
temp = "#FUNCTION bw_defense_enabled {%if(@has_bw AND @bw_defense_issued = 0,1,0)}"
#EXEC {@temp} |
Now, given that, I don't even know why you are doing #EXEC in the first place. Seems like you should just do this directly:
Code: |
#FUNCTION bw_defense_enabled {%if(@has_bw AND @bw_defense_issued = 0,1,0)} |
|
|
|
|
|
|