|
caellin Newbie
Joined: 21 Mar 2007 Posts: 2
|
Posted: Wed Mar 21, 2007 9:04 am
%query and local variables |
I can't seem to get %query to work with local variables
$damage contains decimating
then
$record = %query(damverb=$damage)
gives empty result
if I add
#VAR dam $damage
$record = %query(damverb=@dam)
it give correct record
edited |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Wed Mar 21, 2007 4:33 pm |
I'm sure someone will correct me, but I believe you can't use local variables within functions, at least for now.
|
|
_________________ Asati di tempari! |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Mar 21, 2007 5:33 pm |
You are mixing literal string values with your local variable. You should use %concat explicitly, like this:
Code: |
$record = %query( %concat( "damverb=", $damage)) |
and see if that works any better. |
|
|
|
caellin Newbie
Joined: 21 Mar 2007 Posts: 2
|
Posted: Wed Mar 21, 2007 7:46 pm |
I mistyped it here on forum, should have just copied from the script. Forgot the & when typing it on the forum.
this is how it really looks. and $damage is parameter in the alias.
$record = %query(&damverb=$damage)
gives no record at all.
and
#VAR dam $damage
$record = %query(&damverb=@dam)
gives the right record.
Only difference is using local variable first time.
And second time I copy that variable to another global variable, and then it works.
Tech probably explained it anyway, with not being able to use local variables withing functions. But just corrected what I missed first time anyway. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Wed Mar 21, 2007 9:58 pm |
Can't use local variables in functions!? What kind of absurdity is this!?
#alias test {$one=-285728
#say $one
$two=%abs($one)
#say $two
$three=%eval($two/2)
#say $three}
and, indeed, just about every other application you can think of. Zugg's suggested the proper answer, I think. |
|
|
|
Tech GURU
Joined: 18 Oct 2000 Posts: 2733 Location: Atlanta, USA
|
Posted: Thu Mar 22, 2007 7:42 am |
I stand corrected. My %query was the only time I tried it, and it didn't work. I'll have to update my scripts with Zuggs suggestion.
|
|
_________________ Asati di tempari! |
|
|
|
|
|