|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Mon Dec 08, 2008 1:48 pm
[3.02] #ADD and local variables, possible bug. |
I had a script set up using local variables. The setup contained the following line:
#LOOPDB @IDStats {#ADD $TotalPoints %eval( %float( %val)/%float( 2))}
Oftentimes, when I did a #SAY $TotalPoints, it would return 23.52.54 instead of 12 (2+3.5+2.5+4).
This didn't happen all the time, but enough to make me have to change it to global variables and making sure the variable type was integer, even though it should work with auto-type. To collaborate this point, I decided to run a test:
#ALIAS testmath($Arg1, $Arg2, $Arg3) {#LOCAL $Testmath;#ADD $Testmath $Arg1;#ADD $Testmath $Arg2;#ADD $Testmath $Arg3;#SAY $Testmath}
Then I typed:
testmath 1 2.5 3.5 4
It returned:
12.53.54
Now given there is no way to really specify that a local variable is an integer without using %int($local), this is probably a bug that the autotype for locals is not picking up correctly. Just thought I'd point this out.
Charneus |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Dec 08, 2008 5:58 pm |
#ADD is left over from zMUD compatibility and only worked with integer values. The proper way to do this is to just use the normal addition operator:
Code: |
#LOCAL $Testmath
$Testmath= $Arg1 + $Arg2 + $Arg3
#SHOW $Testmath |
or, for your original script:
Code: |
#LOOPDB @IDStats {$TotalPoints = $TotalPoints + (%float(%val)/2.0)} |
You don't need %eval and instead of %float(2) you can just use 2.0. And you probably don't even need the %float(%val) and could try it with just %val instead. |
|
|
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|