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
edb6377
Magician


Joined: 29 Nov 2005
Posts: 482

PostPosted: Fri Jul 21, 2006 10:09 pm   

[1.03] Variable Expansion in Substitute command
 
I tried to simplify this down maybe you guys can take a look and tell me what new syntax im missing or if this is a bug.

First off i created the Data record variable
Code:

#ADDKEY ItemStatus new %ansi(white)100%
#ADDKEY ItemStatus worn %ansi(green)70%


This works fine. I cant see it in the gui or play with it however running a test of

Code:

#ECHO @Itemstatus.new

shows 100% in white just as it should

Now my problem

i have a trigger
Code:

#TRIGGER {~(({@ItemStatus})~)} {#SUBSTITUTE {%ansi(default)~(@{ItemState.%replace( "%1", " ", "_")}%ansi(default)~)}}


now for simplification of this test i changed it but the above trigger is the one not working as expected.

TEST TRIGGER
Code:

#TRIGGER {~(({@ItemStatus})~)} {#SWITCH (%1=new) {#SUBSTITUTE @{itemstatus.new}} (%1=worn) {#echo @itemstatus.worn}}


Now what i find is that the #ECHO @itemstatus.worn shows the 70% correctly

the #SUB command however no matter how i stick it in there shows the entire variable .new.

I am wondering if the substitute command is having problems with data record variables or if im just too close to it to see what i have done wrong.

SAMPLE OUTPUT
Quote:

<used as light> the crystal of power (worn) (lit)
70%
<worn on finger> the ring of the serpent new100%worn70%.new
<worn on finger> the Ring of Lord Agrippa new100%worn70%.new
<worn on finger> a silver torque ring new100%worn70%.new
<worn around neck> a sigil of restraint new100%worn70%.new
<worn around neck> a sigil of restraint (worn)
70%
<worn around neck> an amulet of spell delivery new100%worn70%.new
<worn on body> a set of overlord armor new100%worn70%.new
<worn on head> the helm of Divusmors new100%worn70%.new
<worn on legs> a polished seashell garter (falling apart)
<worn on feet> boots of resistance (used)
<worn on hands> the gloves of alchemy (worn)
70%
<worn on arms> a baldric band new100%worn70%.new
<worn about body> flowing red robes (slightly worn)
<worn around body> -+=Behold ThE Power Of Cheese=+-
<worn about waist> a seashell belt (slightly worn)
<worn on hip> -+=Tamlin's TokeN Goodie Bag=+- new100%worn70%.new
<worn around wrist> a tooth bracelet new100%worn70%.new
<worn around wrist> a seashell bracelet new100%worn70%.new
<right hand> the banded axe of misery (heavily damaged)
_________________
Confucious say "Bugs in Programs need Hammer"
Reply with quote
Zugg
MASTER


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

PostPosted: Fri Jul 21, 2006 11:44 pm   
 
I think you might need an extra @ within the {}.

The "indirect" variable address syntax is @{expression} The expression is evaluated and then used as the name of the variable.

Now, you have @{itemstatus.new} but "itemstatus.new" is not an expression. So I think you need:

@{@itemstatus.new}

this would evaluate the expression @itemstatus.new and then use the resulting value as the name of the variable.

zMUD didn't handle this syntax very consistently, so I don't really know what worked and what didn't. But the definition in CMUD is very strict and consistent. If you look at the compiled code, you'll see that it evaluates the expression and then calls the VARIND operation to perform the variable lookup.

Also, just a reminder that you can use the #SHOWDB command to display the full value of a database variable from the command line.
Reply with quote
edb6377
Magician


Joined: 29 Nov 2005
Posts: 482

PostPosted: Sat Jul 22, 2006 12:56 am   
 
Unfortunatly you cannot look at the compiled code for triggers.. it was the first tab i looked for and why i like that tab so much. That seems to be for aliases.

I tried @{@Itemstatus.new} which doesnt work and doesnt make any sense to me. Why would i even do that.
@ = Variable

@Itemstatus.new would return ==> 100%

I dont want @100%

So this syntax confuses me a bit. In zmud it had to be @{itemstatus.%1} so it would combine to make @itemstatus.new and wouldnt do @itemstatus then .new

In cmud this seems to have changed but i am a bit perplexed why #ECHO @Itemstatus.new = 100% and #SUB {@itemstatus.new} = nothing.

I would think i should be able to do #SUB {~(@Itemstatus.new~)} and get (100%) on those but it just seems to throw out the entire db when i do that instead of the record i want

Also i have tried this with a variety of commands..

%eval(@itemstate.new) shows properly as long as they are called from ECHO when using #SUBSTITUTE i cant make it work..

Take a minute if you get a chance and try to make a database record list and trigger on it.

i.e.
VAR STATUS
new 100
used 90
slightly used 80

Trigger on (@Status)
#SUB @Status.%1

ADDITIONAL INFO
By sticking @Itemstatus.new in a #VAR i was able to view compiled code. I find this interesting

0000 LINE 0 ; @Itemstatus.new
0012 VARREF @Itemstatus <Itemstatus> (class materiamagica_def) <--- THIS HERE ITS NOT IN THAT PACKAGE NEITHER OF THESE ARE. ITS REFERING TO THE DEFAULT PACKAGE NOT THE PACKAGE ITS IN??
0040 STR '.new'
0060 CONCAT
_________________
Confucious say "Bugs in Programs need Hammer"
Reply with quote
Taz
GURU


Joined: 28 Sep 2000
Posts: 1395
Location: United Kingdom

PostPosted: Sat Jul 22, 2006 3:25 pm   
 
That looks like a cousin of the seperate sessions sharing settings.
_________________
Taz :)
Reply with quote
edb6377
Magician


Joined: 29 Nov 2005
Posts: 482

PostPosted: Sat Jul 22, 2006 5:16 pm   
 
yeah this is one session 3 packages. I create different packages for each Addon for MM.

I am wondering if its likely its because thats where it was last time the code was ran? I have had a few problems creating things in the package i want them in unless i do it manually or move it manually.

I just would like to get the #sub to show what i need it to show
_________________
Confucious say "Bugs in Programs need Hammer"
Reply with quote
Zugg
MASTER


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

PostPosted: Sat Jul 22, 2006 5:45 pm   
 
OK, I misunderstood what you were trying to do. The correct syntax in CMUD is simply @Itemstatus.%1 without any {}. If you wanted to try and use indirection, then the syntax would be @{"Itemstatus."%1}

But, of course, we know that the @Itemstatus.%1 syntax is broken in CMUD, so none of this is going to work until I can fix database variables.

BTW, the "class materiamagica_def" item in the compiled VARREF is *not* the class that it is looking for the variable in. It is the value of the Default class when the alias was compiled. Remember that alias references depend upon the current class. If you do @a, but @a exists in two different classes, then @a has a different value depending upon which class you are in. So the compiler needs to know what class you were in when you references the variable.

When a compiled script is executed, the current class is compared to the default class that was stored when it was compiled. If the current class is the same as the one that was compiled, then the compiled variable reference (the value in the <>) can be used without any problem. If the current class is different, then CMUD does a new lookup on the @varname reference. Doing a new lookup is slower, and since most of the time the current class will be the same, this optimization helps speed up variable lookups.

It's basically like the compiled script has cached a certain reference to the variable within a particular class, so if the class is the same, then it can just used the cached reference.
Reply with quote
edb6377
Magician


Joined: 29 Nov 2005
Posts: 482

PostPosted: Sat Jul 22, 2006 7:10 pm   
 
Okay i understand the .%x syntax isnt working right now.

What i dont understand is why @Itemstatus.New wont work in the sub command either. I think there is another underlying problem here in regards to that.

#ECHO @Itemstatus.new = 100%
#SUB @Itemstatus.new = the whole variable.new
#SUB @{Itemstatus.new}= This is what i used to have to do = whole variable.new
#SUB @{"Itemstatus.new"} = The whole variable.new

I cant seem to pull anything from a datarecord and have it show just the value. It shows the entire db instead, at least with the SUB or %Eval Commands.
_________________
Confucious say "Bugs in Programs need Hammer"
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Sun Jul 23, 2006 1:14 pm   
 
Just quickly popping the 2 commands into an alias and looking at the compiled code a very large difference is immediately seen.
0000 LINE 0 ; #ECHO @TestVar.abc
0012 VARREF @TestVar <?> (class untitled)
0036 STR 'abc'
0056 DOT
0064 CMD echo (1)
0076 LINE 1 ; #SUB @TestVar.def
0088 STR '@TestVar.def'
0116 CMD substitute (1)

It looks like the dot notation does not work for #SUBSTITUTE because the parameter type is set to literal. #PSUB appears to be the same.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
edb6377
Magician


Joined: 29 Nov 2005
Posts: 482

PostPosted: Wed Nov 04, 2009 10:38 pm   
 
is this still broken?
_________________
Confucious say "Bugs in Programs need Hammer"
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