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
trist
Newbie


Joined: 17 Sep 2004
Posts: 5

PostPosted: Tue Jun 12, 2007 9:10 am   

Default Module/Class?
 
Hi all,

I have created a number of modules in cmud which encapsulate some of the functionality (re-written) that I would have originally put in classes in zMud. This seemed to work fine for a period of time, but now, when I create new aliases outide of one of these modules (ie, in my root settings) that set a variable (reading from variables seems to be ok, this just happens when I set them) it seems to want to set them in one of my modules.

Here is an example.

I create the following alias

temp = 1234

Here is the compiled code...

0000 LINE 1 ; temp = 1234
0012 INT 1234
0020 STR 'temp'
0032 ASSIGN

This seems correct to me in that it would create me a @temp variable in the current location (Be it a class or a module).

Now, if I add an #if statement to this command (so, #if (@temp == 1234) {#show yes}) here is the code

0000 LINE 1 ; temp = 1234
0012 INT 1234
0020 STR 'temp'
0032 ASSIGN
0036 LINE 1 ;
#if (@temp == 1234) {#show yes}
0048 PUSHEXP 0064
0056 JUMP 0112
0064 VARREF @temp <?> (class Poison Cure)
0088 INT 1234
0096 NEQ
0100 SETEXP 0 0
0112 ARGSTR @temp == 1234
0136 PUSHLOC 0152
0144 JUMP 0176
0152 STR 'yes'
0164 CMD show (1)
0176 ARGSTR #show yes
0196 CMD if (2)

This doesn't appear to cause a problem (the variable is set correctly, in the right place), I am just wondering why the compiled code has a reference to 'class Poison Cure' when this alias has nothing to do with it?
Reply with quote
trist
Newbie


Joined: 17 Sep 2004
Posts: 5

PostPosted: Tue Jun 12, 2007 9:24 am   
 
Infact it might be causing a problem when I try to print the variable in my status bar... If I just have

<@temp>

in a statusbar, the compiled code is

0000 LINE 0 ; <@temp>
0012 STR '<'
0024 VARREF @temp <?> (class Poison Cure)
0048 CONCAT
0052 STR '>'
0064 CONCAT

If I then do temp = 12345 on the command line (which creates the variable in the root location of my settings file, it doesn't pick up the variable. If I move the variable to the 'Poison Cure' module, it then picks it up...!
Reply with quote
Fang Xianfu
GURU


Joined: 26 Jan 2004
Posts: 5155
Location: United Kingdom

PostPosted: Tue Jun 12, 2007 10:13 am   Re: Default Module/Class?
 
trist wrote:
when I create new aliases outside of one of these modules that set a variable it seems to want to set them in one of my modules.

So you've created an alias that's creating variables outside its module? Or do the modules contain variables of the same name and the alias is choosing the wrong one? Are all of the modules part of the same package? Have you tried double-clicking on the variable names in the alias code to check that it's referring to the right one?
_________________
Rorso's syntax colouriser.

- Happy bunny is happy! (1/25)
Reply with quote
trist
Newbie


Joined: 17 Sep 2004
Posts: 5

PostPosted: Tue Jun 12, 2007 10:20 am   
 
I've created an alias that should reference variables in it's own class (the window). The modules do not contain variables of the same name, but the alias that I created is looking for the variable in the module, and not in the window like I would expect.

All of the modules are indeed part of the same package.. so its like this:

Window
|
-- classes
| |
| -- location in class where I want to create the alias described above
|
-- Poison Cure (module)
-- Another Module 1
-- Another Module 2
-- Another Module 3

So everything is under the window, some aliases/classes are in the window itself (where I want to store all the 'global' aliases/etc that don't yet belong in a module), and some are in modules (where I have moved them out).

Make sense?
Reply with quote
Tech
GURU


Joined: 18 Oct 2000
Posts: 2733
Location: Atlanta, USA

PostPosted: Tue Jun 12, 2007 4:08 pm   
 
It sounds like what is happening is that the 'current' module is being changed by some other script or command using the #MODULE command and is not being changed back.

You have several choices here. You can explicitly tell your alias to use a specific module or class using using their respective commands (#MODULE ro #CLASS).

Alternatively you can explicitly define the variable in the module or class you wish instead of assuming the current scope. Try

//MyModuleorWindow/MyClass1/MySubClass2/MyVariable=50

or

#VAR //MyModuleorWindow/MyVariable Warrior.

I hope that helps.
_________________
Asati di tempari!
Reply with quote
Zugg
MASTER


Joined: 25 Sep 2000
Posts: 23379
Location: Colorado, USA

PostPosted: Wed Jun 13, 2007 4:19 pm   
 
The Class that is being shown in the compiled code for the VARREF statement is showing the value of the "current class" when the alias was compiled. The VARREF stores the database reference to the variable at compile time, but also stores the string name of the variable and the current class value, so that CMUD can determine if something has changed since it was compiled.

For example, if you have two variables with the same name (@temp), but in different classes (Class1 and Class2), then when you reference @temp, it depends upon which class is the current class. If you create an alias (or any other setting) that references @temp, then CMUD stores the current class. When you run the alias, it checks to see if the current class is the same as the one stored in the compiled code. If it's the same, then the compiled variable reference is still valid. If the current class is different than what was stored in the compiled code, then CMUD does a new lookup of the stored string name of the variable so that the proper variable reference is obtained.

So, to summarize, the Class name shown in the compiled VARREF code is *not* the name of the class that contains the variable. Is it simple whatever the current class was when the alias was compiled.
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