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

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » CMUD General Discussion
thomaspepon
Beginner


Joined: 04 Sep 2008
Posts: 16

PostPosted: Sat Dec 27, 2008 3:52 am   

syntax issue with variable assignment
 
I'm trying to convert to CMUD from zMUD, and am working on some of the syntactical differences,
but I have come across what seems to be a simple variable assignment that isn't working correctly.

I have an alias named blah_prac_new in class Practice with code as follows:
#VAR prac_1 {"#ti 0;wa;.3d2s"|"#6 dr jug;fil jug;.2n3u"}
#ALARM "prac_1_exec" {*5} {
#exec %pop( prac_1)
#IF !(@prac_1) {
#UNTRIG prac_1_exec
#UNVAR prac_1
#VAR prac_count {0}
#ALARM "prac_2" {*6} {
#if (@prac_count < @practice_count) {
#show @prac_count
#exec practice_action
#add prac_count 1
} {
#UNTRIG prac_2
#UNVAR prac_count
sl
pra
tel blah blah_practice complete!
}
}
}
}

It creates a variable named prac_count which I think is where my issue lies, maybe a scoping problem.
This works just fine, and practice_action is another alias which casts a variable spell on a variable target.

I created a trigger on "You don't have enough mana." to set @prac_count = @practice/practice_count, so
that the above loop would exit, since the if statement would fail if the created @prac_count was equal to
the variable practice count in class practice.

When I create variable prac_count, it seems that it is created at the base level, and not within the class Practice.
It seemed to work this way in zMUD, and the above code was fine. However, when I get the "You don't have
enough mana." trigger firing in CMUD, I get:
ERROR: Trigger "You don't have enough mana." fired but did not compile

I also tried setting up the trigger assignement as
@practice/prac_count = @practice/practice_count
and
@prac_count = 50
neither of which seems to work.

I'm not sure what is wrong with my setup. Any help would be appreciated.
Reply with quote
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Mon Dec 29, 2008 1:22 am   
 
I don't believe it matters what class your alias is defined in for CMUD. If you create a variable inside the alias and that variable does not already exist in the practice class, the variable will be created in the "current" class. By default, there is no current class, which means the variable will be created in the main session module.

You can set your current class using
Code:
#class practice
prior to creating the new variables in your alias. The current class can then be set back to the default of 'none' using
Code:
#class 0

Alternatively, you can create the variable in the desired class using some extra parameters to the #var command.
Reply with quote
thomaspepon
Beginner


Joined: 04 Sep 2008
Posts: 16

PostPosted: Mon Dec 29, 2008 2:55 am   
 
Thanks for the assistance calesta. I'm not sure about the scope issue. I had
these assignment errors all over the place. I tried creating the variable in class
practice by adding the extra parameter, but it still was being created at the base
level. Not sure what the deal was there...

Syntax checking is a beautiful thing. Whenever I removed the @ from
in front of the variable name, it started clearing the syntax check.

The solution was to make the script read
prac_count = practice_count

I have a lot of things to clean up, because I had a lot of variable assignments in the
scripts I brought over. But at least I have one thing corrected. Thank goodness.
Reply with quote
calesta
Apprentice


Joined: 07 Dec 2008
Posts: 102
Location: New Hampshire, USA

PostPosted: Mon Dec 29, 2008 4:36 am   
 
I didn't notice the assignment mistake in the original post. You should only use the @ to access the value in a variable, not when assigning a value to a variable.

I tried getting the variables created in a separate class with the #var command and it works OK for me. Maybe you had a syntax mistake there or the variable already existed. Here is what worked for me to create variable prac_count inside the practice class with no default value and a current value of 0:
Code:
#var prac_count 0 _nodef practice
However, if the variable prac_count had already existed somewhere else, this would have just updated the existing variable's value, not created a new variable in the specified class.

You could also accomplish this by creating the variable with the alternate syntax:
Code:
practice/prac_count= 0
Doing it this way guarantees that the prac_count variable will always be created and updated in the practice class, even if the prac_count variable exists somewhere else. I'm not sure why the #var command doesn't work this same way when a class is specified, maybe someone else can shed some light on that.
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » CMUD General Discussion 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