|
Meznev Newbie
Joined: 22 Sep 2005 Posts: 6
|
Posted: Fri Sep 23, 2005 2:26 pm
[solved] Variable classes, functions? |
I have an issue, apparently. I have several aliases that all use the same chunk of 'code', and that code always uses the same variables, and they're all in the same class.
However, what happens is that when that code chunk is run by anything, it creates classless versions of the variables even though there's a version that exists in the same class as the alias. And my aliases seem to like to use that over the vars within the same class. Is there an easy way to fix that?
And, I'd like to know if there's a more elegant solution to my other problem. I've tried using 'functions' in zmud, but apparently by 'function', zmud means 'a list of stuff to spew at the mud'. I have the aformentioned code chunk, and it takes two arguments. I'd like to just be able to toss the two arguments at a 'function', and have it run the code, set the vars, and return like a normal c-like function does. Minus spew-to-mud unless told to do so. Is there any way to achieve that? Right now the bit is only about 12 lines long, but its in about 20 different aliases. Would be nice to be able to update a central bit to update all 20.. :) |
|
Last edited by Meznev on Sat Sep 24, 2005 7:51 pm; edited 1 time in total |
|
|
|
JQuilici Adept
Joined: 21 Sep 2005 Posts: 250 Location: Austin, TX
|
Posted: Fri Sep 23, 2005 7:51 pm |
Can you post one of your existing aliases that demonstrates this behavior? It'll help make the discussion a lot more concrete.
That said, I finally got my mind around this recently. My problem had been that I was creating classed variables improperly. For instance, I would have a line like this inside an alias in my "Ident" class:
Code: |
#var obj {somevalue} Ident
|
And I couldn't understand why I wouold wind up with the variable 'obj' in the top scope. Of course, the problem was that I had too few arguments - the third argument to #var is the default value (which was silently discarded because I supplied a value), and the fourth argument is the class. So the line should be:
Code: |
#var obj {somevalue} {} Ident
|
Once I fixed this, all my variables were properly scoped. |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Fri Sep 23, 2005 8:37 pm |
Jquilici, if you wish to not have and actual default you must use _nodef for your third parameter. This can be delimited by either quotes or braces.
Meznev, there are many cases where a default class is defined by another portion of your script and not released. It is a best practice to never use #CLASS {name}...#CLASS 0 within a trigger as the timing of execution of scripts is optimized in such a way that the 2 #CLASS might not be executed in a contiguous block. This is what the #PRIORITY command is for. I would definitely suggest posting the the full script causing problems; or if you feel uncomfortable with such, posting the portions that you feel are the most likely culprits. If we don't have enough information to solve the problem from your further posts we will say so. |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Meznev Newbie
Joined: 22 Sep 2005 Posts: 6
|
Posted: Fri Sep 23, 2005 11:50 pm |
Here's an example of what I'm talking about. I type spellup <power/target> <target> and it casts a spell.
spellup 21 someone will do "weave 21 'shield' someone" and if I type spellup 123 will do "weave 123 'shield'". If I spec a power it'll 'remember' it and attempt to use that later (potentially dangerous in the mud I play, but its handy).
Code: |
//#echo Test: 1(%1) 2(%2)
//Re-initialize these vars. I'm sure there's a local var thing in zmud, but I don't know it.
@one =
@target =
#if (%1) {
@one = %1
#if (@one =~ "%d") {@power = @one}
#if (@one =~ "%w") {@target = @one}
}
#if (%2) {@target = %2}
//#echo 1(@one) 2(@target) 3(@power)
//#echo --------------------------------------
weave @power 'shield' @target
|
The chunk before the weave line is in a bunch of different aliases, and is the part I'd like to be able to turn into like a normal c-like function. I've tried to create an alias with it and call it from within another alias, and it works, but it sends alot (about 5-8) blank lines to the mud.. any way to figure out what's doing that?
For the variables, would the #CLASS command be appropriate here? Maybe that's what I've been missing? |
|
|
|
shalimar GURU
Joined: 04 Aug 2002 Posts: 4672 Location: Pensacola, FL, USA
|
Posted: Sat Sep 24, 2005 8:29 am |
When using the 'variable = value' syntax of defining variables, leave off the '@' symbol. So instead of:
@power = @one
You get:
power = @one
Unless the value of @power is the variable name you are trying to redefine. |
|
_________________ Discord: Shalimarwildcat |
|
|
|
Vijilante SubAdmin
Joined: 18 Nov 2001 Posts: 5182
|
Posted: Sat Sep 24, 2005 1:53 pm |
one = ""
target = ""
#if (%1) {
one = "%1"
#if (@one =~ "%d") {power = @one}
#if (@one =~ "%w") {target = @one}
}
#if (%2) {target = %2}
//#echo 1(@one) 2(@target) 3(@power)
//#echo --------------------------------------
weave @power 'shield' @target |
|
_________________ The only good questions are the ones we have never answered before.
Search the Forums |
|
|
|
Meznev Newbie
Joined: 22 Sep 2005 Posts: 6
|
Posted: Sat Sep 24, 2005 7:03 pm |
Wow, that works really well. It still wanted to create @target as a unclassed var, but that's okay. I just inserted a #class statement and now it works. I even got passing stuff to it working properly. I had to take out the // commands to get it to stop pushing out blank lines, but that's okay. I have the original alias I can use to test changes with.
Thanks guys, I really really appreciate the help. This is what I ended up with, takes two args, sets @power and @target, and works like a charm now:
Code: |
#class spells
one = ""
target = ""
#if (%1) {
one = "%1"
#if (@one =~ "%d") {power = @one}
#if (@one =~ "%w") {target = @one}
}
#if (%2) {target = %2}
|
|
|
|
|
|
|