Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD Beta Forum
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Mon Nov 02, 2009 6:59 pm   

[3.12] Local variable alias not compiling
 
Hi all, I'm working on a script, where I have the following in alias 1:

#ADDKEY SpellupVar AliasSoon {%null}
#LOOPDB @SpellupSubClass {#IF (%val=1) {#IF (%null( %db( @SpellupVar, AliasSoon))) {#ADDKEY SpellupVar AliasSoon {SpellupCast Self '%key'}} {#ADDKEY SpellupVar AliasSoon %concat( %db( @SpellupVar, AliasSoon), ~;SpellupCast Self '%key')}}}
$SpellupToBeRecastTemp=%db( @SpellupVar, AliasSoon)
#ALIAS SpSubClass {$SpellupToBeRecastTemp}
#ADDKEY SpellupVar AliasSoon %replace( %db( @SpellupVar, AliasSoon), SpellupCast Self, c)
#SAY %ansi( green, hi)New alias for SpSubClass: %db( @SpellupVar, AliasSoon)!

and the following in alias 2:

#ALIAS SpellupToBeRecast {%null}
#ADDKEY SpellupVar AliasSoon %null
#LOOPDB @SpellupAllSpellsOnMe {#IF (%val=1) {#IF (%null( %db( @SpellupVar, AliasSoon))) {#ADDKEY SpellupVar AliasSoon {SpellupCast Self '%key'}} {#ADDKEY SpellupVar AliasSoon %concat( %db( @SpellupVar, AliasSoon), ~;SpellupCast Self '%key')}}}
#IF (%null( %db( @SpellupVar, AliasSoon))) {#ALIAS SpellupToBeRecast {%null}} {
$SpellupToBeRecastTemp=%db( @SpellupVar, AliasSoon)
#ALIAS SpellupToBeRecast {$SpellupToBeRecastTemp}
SpellupToBeRecast
}

Alias 2 compiles without problem. But for Alias 1, I get this error:

Error compiling script:
invalid local variable: SpellupToBeRecastTemp

Can someone explain to me why I get this error message?

With regards
DanteX
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Tue Nov 03, 2009 1:28 pm   
 
Copying what you have shown for alias 1, I get no error. It compiles just fine.

The particular error you are getting occurs when a local variable is used before it has been initialized. Local variables can be initialized with a #local statement, or by assigning a value to it, e.g. $SpellupToBeRecastTemp=whatever. You are initializing the variable with the second method--your script should be just fine. Are you absolutely certain that you have copied the alias here as it is in your package? Another thing to check is whether there is another, incorrect, copy of alias 1 somewhere in your packages, which is throwing this error.
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Tue Nov 03, 2009 3:04 pm   
 
A followup:

In the alias, that contained the non-working code, the last 4 lines were idented with 4 x white space at the beginning of each line.

In the alias that contained the working code, the 2 last lines were identented with 4 x white space, and the lines containing the temp-var, were identented 3 lines. This said, it means that identing lines may result in a non-compiled code.

Both these setups were results of pressing CTRL+M.

When I manually remove all identing, all compile.

//DanteX
Reply with quote
Rahab
Wizard


Joined: 22 Mar 2007
Posts: 2320

PostPosted: Wed Nov 04, 2009 5:22 pm   
 
Yes, indenting has meaning in Cmud. Are you certain that the indenting did not get accidentally changed afte doing CTRL-M? I cannot get it to produce the results you report.
Reply with quote
DanteX
Apprentice


Joined: 13 Aug 2007
Posts: 166

PostPosted: Wed Nov 04, 2009 5:30 pm   
 
I am 100% sure that CTRL+M reulted in the indenting, since that's what I used because the alias was all in "one line" with ";" as separators all the way, may that original state made it indent wrongly?

I dunno what caused all of my problems... This was on a package imported from zmud, and I've now created a new session and moved on there... It works fine at least after the indenting is fixed.

//DanteX
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD Beta Forum All times are GMT
Page 1 of 1

 
Jump to:  
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

© 2009 Zugg Software. Hosted by Wolfpaw.net