|
saet Apprentice
Joined: 12 Jun 2006 Posts: 106
|
Posted: Sat Sep 23, 2006 4:48 am
[1.07] Local Variable issue |
This is my alias script:
$round1 = %gsl(Q)
$round2 = %gsl(q)
#IF ($round1=@roundCheck) {#ABORT 1}
#IF ($round1>$round2) {
roundCheck = $round1
$round3 = %eval($round1-$round2)
#SHOW $round3
} {$round1=1}
//#SHOW $round3
#IF ($round1 > 100) {
#ECHO Unexpected Roundtime: $round1
$round1 = 10
}
roundTime = $round1
rtGaugeMax = $round1
The #SHOW $round3 that is commented out causes some major issues. I know that it's a bad spot to have it because there is a chance that it's never assigned. That's where I originally had the show and when that bit is uncommented no commands in the alias are processed by CMUD, everything is sent literally to the mud like so:
> app pouch
The fletching pouch is a container, and can be opened and closed.
The fletching pouch is incredibly pliant.
It appears that the fletching pouch can be worn attached to a belt.
The fletching pouch feels pretty light.
You are certain that the fletching pouch is worth exactly 87 kronars.
Roundtime: 8 seconds.
> $round1 = %gsl(Q)
$round2 = %gsl(q)
#IF ($round1=@roundCheck) {#ABORT 1}
#IF ($round1>$round2) {
roundCheck = $round1
$round3 = %eval($round1-$round2)
#SHOW $round3
} {$round1=1}
#SHOW $round3
#IF ($round1 > 100) {
#ECHO Unexpected Roundtime: $round1
$round1 = 10
}
roundTime = $round1
rtGaugeMax = $round1
blah <-- this is from a pattern trigger that goes off the word roundtime
Please rephrase that command.
Please rephrase that command.
Please rephrase that command.
Sorry, you may only type ahead 1 command.
Please rephrase that command.
Sorry, you may only type ahead 1 command.
Please rephrase that command.
I sent in a bug report when I tried to close a window and it crashed CMUD after I was having this problem. I incorrectly stated that another trigger was doing the same thing, I was wrong, I didn't realize I had #SHOW blah at the beginning of the alias before and got it confused with a trigger that did a #SHOW blah also.
I tried doing a #ADD $round1 (-$round2) because that is how I did it in zMUD with regular variables. It doesn't work with locals. |
|
Last edited by saet on Sat Sep 23, 2006 4:52 am; edited 1 time in total |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Sat Sep 23, 2006 4:51 am |
There are a couple of other bug reports in my database regarding local variables. I haven't had a chance to look at them yet and did not fix anything regarding local variables in 1.06. But it's on the bug list.
|
|
|
|
saet Apprentice
Joined: 12 Jun 2006 Posts: 106
|
Posted: Sat Sep 23, 2006 5:05 am |
I realized I forgot to change my $round1's after the second #IF statement to $round3. When I did that I ran into the same problem.
|
|
|
|
Larkin Wizard
Joined: 25 Mar 2003 Posts: 1113 Location: USA
|
Posted: Sat Sep 23, 2006 12:17 pm |
I'm not sure if CMUD uses the traditional C-like definition of scope, but if it does, that $round3 local variable is undefined outside of the curly braces and will cause the commands referencing it to fail. You -should- be able to get around that by setting $round3 to anything (0, probably) right at the beginning, just to create the variable. It would be good to get clarification on local variables and how the scoping works in CMUD, too.
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Sep 25, 2006 8:30 pm |
Actually, Larkin is correct on this. Local variables are created when you first assign to them. Your $round3 is created and assigned within the block of the
#IF ($round1>$round2) {
statement, and is thus local to that IF statement. You cannot access $round3 from outside the IF statement. If you want to access $round3 outside of the #IF statement, then you need to assign/create it at the beginning of the script like you do with $round1 and $round2
So, this isn't a bug in CMUD, it's a bug in your script.
Also, any script that doesn't compile is treated as a normal string value by CMUD, so scripts with syntax errors can end up sending their contents to the MUD. |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4715 Location: Pensacola, FL, USA
|
Posted: Tue Sep 26, 2006 11:39 pm |
also, the gsl variables got updated to use %gsl.Q
not %gsl(Q) |
|
_________________ Discord: Shalimarwildcat |
|
|
|
saet Apprentice
Joined: 12 Jun 2006 Posts: 106
|
Posted: Tue Sep 26, 2006 11:50 pm |
works either way
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Sep 27, 2006 1:41 am |
Both syntaxes for %gsl are supported for compatibility and will be for the forseeable future.
|
|
|
|
|
|