|
The Raven Magician
Joined: 13 Oct 2000 Posts: 463
|
Posted: Mon Aug 27, 2007 5:37 pm
[2.01] Cross-Module Variable Referencing |
I have two modules in a package. It's pretty simple... one trigger, one alias, and two variables.
I'm a bit puzzled though why it's not working. It's simple and straightforward.
Every time I type the alias 'bbread', the number should increment by one, so that next time I type the command, it will show me the next post on the same board. Unfortunately, it does not do this, and I can't figure out why. Also, classes named 'BB' appear in other modules.
Either I'm doing something wrong, or 'private' modules aren't working properly. Here is the XML to the two modules (I have them in one package named 'BB', but I'm not certain that should change anything):
<module name="BB">
<uid>{ACECFB4D-0B61-40D5-B58C-CBBB0CF0A3D7}</uid> <var name="bbnext" type="String" default="u" usedef="true" saved="false" id="2">99</var>
<var name="bbboard" type="String" id="4">1</var>
</module>
<module name="Interface" id="5">
<uid>{B5D3D248-E333-4AEA-8F76-BCB0C7EE2D2C}</uid> <alias name="bbread" id="1">
<value>
#IF ($post > 0) {#VAR bbnext {$post} _nodef {//BB}}
#SEND {+bbread @//BB/bbboard/@//BB/bbnext}
</value>
<arglist>post</arglist>
</alias>
<trigger priority="30" case="true" id="3">
<pattern>^Message: (%d)/(%d)</pattern>
<value>
#VAR bbboard {%1} _nodef {//BB}
#VAR bbnext {%eval(%2+1)} _nodef {//BB}
</value>
</trigger>
</module>
The alias 'bbread' takes one argument, which lets you specify a different post than the default next one.
The trigger finds lines that look like "Message: 3/14 ...". 3 would be the board, and 14 would be the post. It adds one to the post number, and saves that into @bbnext.
@bbnext and @bbboard are stored in the private BB module. This is the part that appears to be broken (the fact that it is private). It's not strictly NECESSARY for private variables, but I'd really like to have this work, since I'm not a fan of global namespace pollution. |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Aug 27, 2007 7:19 pm |
You shouldn't be using the Class argument of #VAR to specify the module name. You are making this too hard on yourself. Also, in your #SEND command, you need some {} around the variable names to avoid confusing the parser. Here is the correct syntax for your alias:
Code: |
#IF ($post > 0) {//BB/bbnext = $post}
#SEND {+bbread @{//BB/bbboard}"/"@{//BB/bbnext}} |
and here is the trigger:
Code: |
//BB/bbboard = %1
//BB/bbnext = %2+1 |
Give that a try and see if it works any better. |
|
|
|
The Raven Magician
Joined: 13 Oct 2000 Posts: 463
|
Posted: Mon Aug 27, 2007 7:27 pm |
That works just fine. So... does that mean #VAR {var} {value} {default} {//module/class} syntax is broken? Should that be deprecated or abandoned?
|
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Mon Aug 27, 2007 7:34 pm |
I think the //module/class in the #VAR command is broken, and I've added it to my bug list. But it's so much easier to read the newer syntax that I'd avoid using #VAR for complicated stuff like this.
Also, calling #VAR is slower than using the var=value syntax since the var=value syntax is built directly into the compiler, where as #VAR has the overhead of a command call. |
|
|
|
The Raven Magician
Joined: 13 Oct 2000 Posts: 463
|
Posted: Mon Aug 27, 2007 7:45 pm |
Hrm. Can you dereference variable names using that syntax? What's the equivalent to this?
#VAR @Foo {value} {} {//class/path}
This does not compile, for obvious reasons:
//class/path/@Foo = value
Is there a workaround? |
|
|
|
Thinjon100 Apprentice
Joined: 12 Jul 2004 Posts: 190 Location: Canada
|
Posted: Mon Aug 27, 2007 7:51 pm |
There's probably an easier way, but you can always do #EXEC %concat("//class/path/",@Foo." = value") to do this.
I'm not too well-versed in the {} syntaxes in CMud yet (I'm still stuck in my old zScripting mindset)... but have you tried something like:
//class/path/{@Foo} = value ?? I haven't tried it, but it might work. |
|
_________________ If you're ever around Aardwolf, I'm that invisible guy you can never see. Wizi ftw! :) |
|
|
|
Zugg MASTER
Joined: 25 Sep 2000 Posts: 23379 Location: Colorado, USA
|
Posted: Wed Aug 29, 2007 7:54 pm |
I believe just putting () around the expression will do it. For example:
#VAR (@Foo) {value}
I don't think you can do indirect assignment with the varname=value syntax. |
|
|
|
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Wed Aug 29, 2007 8:05 pm |
For LOCAL variables it makes you use %eval() () isn't enough I haven't tried it with normal variables.
|
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
|
|
|