|
Rappy Wanderer
Joined: 15 Jul 2005 Posts: 96
|
Posted: Sun May 18, 2008 1:40 pm
variables inside classes |
This should be easy, but I can't find the answer in the help at all (hint hint, fix help). How do I access a variable that is in a class other than default class?
-Rappy |
|
_________________ Windows 11 Pro,
cMUD 3.34 |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun May 18, 2008 1:52 pm |
As long as there's not another variable with the same name, just using its name will work.
|
|
|
|
Rappy Wanderer
Joined: 15 Jul 2005 Posts: 96
|
Posted: Sun May 18, 2008 1:59 pm |
That's the problem, I have the same variable under different classes (multiple users for the same MUD) I suppose I can dynamically name them based on character name, but this way seems easier if I can just access the variable under the individual class.
IE. Character Name Rappy has a Class Rappy and within that class has a variable @weapon (for disarm triggers). Each character has his/her own class (and duplicate variables for some)
The triggers are setup to grab the variable in default class, there has to be a way to tell it what class to get the variable from.
-Rappy |
|
_________________ Windows 11 Pro,
cMUD 3.34 |
|
|
|
Rappy Wanderer
Joined: 15 Jul 2005 Posts: 96
|
Posted: Sun May 18, 2008 5:32 pm |
Lack of response makes me think there is no easy solution... does that mean there is no support to get that info? Why can we make variables inside class folders if there is no way to access them?
-Rappy |
|
_________________ Windows 11 Pro,
cMUD 3.34 |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun May 18, 2008 6:09 pm |
It's been three and and a half hours. Have patience. I don't have zMUD installed, so I can't remember what's supported and what isn't. IIRC, it's @class/var, but, like I said, I'm not sure and can't check.
|
|
|
|
MattLofton GURU
Joined: 23 Dec 2000 Posts: 4834 Location: USA
|
Posted: Sun May 18, 2008 6:14 pm |
Dude, you've posted a question in prime church-going time. Even for those who don't practice, we're usually out to breakfast/brunch or doing things that take us away from the computer now.
To answer your question, though, use the #VARIABLE command.
#VARIABLE varname {variable contents} {default contents} "class"
If you don't specify class, ZMud just goes looking for the first-found match and it does this in a top-down manner. For example, after the default class it then checks the None folder (root class). From there, the next in line is the Autolog folder but since this class is disabled already it jumps into the System folder. Within the System folder it jumps into the Automapper folder. By default there's no other folders in here, so the next folder it checks would be the AutomapperAll folder. It repeats this all the way down to the last subfolder in System. After that, let's say next comes Rappy and within it comes the Weapons, Skills, and Places folders. Within Weapons you have Blades, Clubs, and Bows. Before ZMud goes into the Skills folder, it will travel through Blades, Clubs, and Bows in that order. |
|
_________________ EDIT: I didn't like my old signature |
|
|
|
Rappy Wanderer
Joined: 15 Jul 2005 Posts: 96
|
Posted: Sun May 18, 2008 6:48 pm |
Matt, I know how to assign the variable to the class, but I can't seem to recall that specific variable later.
#TRIGGER {You wield &{temp}.} {
#VARIABLE temp %remove( mithral, %remove( dragon, %remove( " of Zamiel", %remove( hilted, %remove( "an ", %remove( "a ", @temp))))))
#SAY @temp
#IF (%ends( @temp, off-hand)) {#VARIABLE offhand %remove( " in your off-hand", @temp) "" @nick} {#VARIABLE weapon @temp "" @nick}
#UNVAR temp
}
#TRIGGER {* DISARMS you and sends your %w weapon flying!} {
get '%if( %1 = primary, @weapon, @offhand)'
#IF (%1 = primary) {wield @weapon} {dual @offhand}
}
The above works IF I don't put the variable in the sub-class, but the problem is, different characters try to wield other characters weapons when they are disarmed (whoever last set the variable) I am sure I can %concat a variable with @nick and @weapon in the default class to do what I want, but I would like to know how to find the specific variable I set in the subclass, rather than the heirocratic search through the classes.
-Rappy |
|
_________________ Windows 11 Pro,
cMUD 3.34 |
|
|
|
ralgith Sorcerer
Joined: 13 Jan 2006 Posts: 715
|
Posted: Sun May 18, 2008 8:37 pm |
Well, A far simpler solution is to create a separate character icon for each character so they can each have unique settings. But yes, you can use @class/var as Fang mentioned.
To quote the zmud Help file:
Quote: |
Class Character
The class character can be used to specify a path to a setting. This is useful if you want to have multiple variables, aliases, or any other setting of the same name. It can be used in the class parameter of commands or immediately before the settings name. Periods can be used to designate root (None) class and parent class when a default class is used.
Examples:
#ALIAS ex {example1} /class1
Creates the alias in class1 as a subclass of current default class.
#ALIAS ./class2/ex {example2}
Creates the alias in class2 from the root
#CLASS class3
#ALIAS ex {example3} ../
#VAR test abc
#CLASS 0
Creates the alias in the parent class of class3 and the varaible in class3
#SHOW @test
#SHOW @./test
class2/ex
Would display abc, followed by a blank line because test is not found in the root class, then send example2 to the mud. |
So, you'll want:
#TRIGGER {* DISARMS you and sends your %w weapon flying!} {
get '%if( %1 = primary, @Rappy/weapon, @Rappy/offhand)'
#IF (%1 = primary) {wield @Rappy/weapon} {dual @Rappy/offhand}
}
Of course, I still prefer the unique settings file per character. |
|
_________________ CrossOver: Windows Compatibility on Mac and Linux CMUD Advocate |
|
|
|
Zhiroc Adept
Joined: 04 Feb 2005 Posts: 246
|
Posted: Sun May 18, 2008 8:38 pm |
Fang gave you the answer in his last post: @class/varname
You can even set variables this way: #VAR class/varname {value}
I like that since I then don't have to specify the default value.
BTW, if you want no default value, use {_nodef}. I think "" would end up setting a blank default value, meaning that the variables would reset. |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun May 18, 2008 10:17 pm |
Zhiroc is right about default values. You need to use _nodef for no default - any other value, even null, becomes the default.
|
|
|
|
Rappy Wanderer
Joined: 15 Jul 2005 Posts: 96
|
Posted: Mon May 19, 2008 1:23 am |
Ok, not sure what the problem is here. Using @class/variable works, but only seems to work from the command line, in the script it is returning %null for some reason. I have the variable setting correctly, changed "" to {_nodef} and still no change, the script is still returning %null for the variable.
Curious, could it be that the class itself is being called as a variable? I admit that ralgith is right, having different settings for different characters, but at this point everything is so integrated, it would be a nightmare sorting it all out. A few of the characters use the same triggers and variables.
When I sign on, I use #PICK, then set @nick with the character I am using. In the disarm script, I was using @nick/weapon, and I think that is why, it is looking for variable weapon in class Nick, which doesn't exist. So how can I get it to get the correct variable using a variable as the class?
Problem is, is that when @nick is evaluated, it messes up the @class/variable 'routine' to get the correct variable.
-Rappy |
|
_________________ Windows 11 Pro,
cMUD 3.34 |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon May 19, 2008 3:44 am |
@{@nick/weapon} may work.
It'd probably be much easier to change this script some, perhaps to using data record variables to store data (where the key is the nick and the value is the value for that nick). CMUD also has many tools to make sharing scripts across characters like this easier, if you want to try that. |
|
|
|
Rappy Wanderer
Joined: 15 Jul 2005 Posts: 96
|
Posted: Mon May 19, 2008 4:50 am |
None of those worked... tinkering around with Fang's last suggestion, I came upon this that did work.
Code: |
#TRIGGER {You wield &{temp}.}
#VARIABLE temp %remove( mithral, %remove( dragon, %remove( " of Zamiel", %remove( hilted, %remove( "an ", %remove( "a ", @temp))))))
#IF (%ends( @temp, off-hand)) {#VARIABLE offhand.@nick %remove( " in your off-hand", @temp)} {#VARIABLE weapon.@nick @temp}
}
#TRIGGER {* DISARMS you and sends your (%w) weapon flying!} {
#IF (%1 = primary) {
get @{weapon.@nick}
wield @{weapon.@nick}
} {
get @{offhand.@nick}
dual @{offhand.@nick}
}
}
|
Thanks for all the help. Sorry for acting impatient.
-Rappy |
|
_________________ Windows 11 Pro,
cMUD 3.34 |
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Mon May 19, 2008 5:10 am |
I'm suprised no one suggested variable databases. For instance, instead of @weapon in the Rappy class, why not have a weapon key in a Rappy variable?
#SHOW @{@nick}.weapon (I believe is the right syntax) would be a lot easier. Then you can change your @nick to your current character name, and it'll pull the information as needed.
Charneus |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon May 19, 2008 5:20 am |
charneus wrote: |
I'm suprised no one suggested variable databases. |
Fang Xianfu wrote: |
It'd probably be much easier to change this script some, perhaps to using data record variables |
|
|
|
|
charneus Wizard
Joined: 19 Jun 2005 Posts: 1876 Location: California
|
Posted: Mon May 19, 2008 6:58 am |
Haha. Wow. I can't believe I missed that. Then again, Rappy's last example is working in that direction, and I sort of missed that. I need to read things more closely before posting from my phone. Heh. Sorry, Fang.
Charneus |
|
|
|
Rappy Wanderer
Joined: 15 Jul 2005 Posts: 96
|
Posted: Mon May 19, 2008 5:13 pm |
Changed using database per nick.
Code: |
#TRIGGER {You wield &{temp}.}
#VARIABLE temp %remove( mithral, %remove( dragon, %remove( " of Zamiel", %remove( hilted, %remove( "an ", %remove( "a ", @temp))))))
#IF (%ends( @temp, off-hand)) {#VARIABLE <@nick>.offhand %remove( " in your off-hand", @temp)} {#VARIABLE <@nick>.weapon @temp}
}
#TRIGGER {* DISARMS you and sends your (%w) weapon flying!} {
#IF (%1 = primary) {
get %concat( ~", @{<@nick>.weapon}, ~")
wield %concat( ~", @{<@nick>.weapon}, ~")
} {
get %concat( ~", @{<@nick>.offhand}, ~")
dual %concat( ~", @{<@nick>.offhand}, ~")
}
}
|
Works a little nicer, harder to get the variable though, but in the end is more versitle.
-Rappy |
|
_________________ Windows 11 Pro,
cMUD 3.34 |
|
|
|
Fang Xianfu GURU
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon May 19, 2008 5:40 pm |
You don't need to ue that @{<@nick>.something} stuff, just use the %db function. %db(@{@nick},"something") should work and looks a little better.
|
|
|
|
Rappy Wanderer
Joined: 15 Jul 2005 Posts: 96
|
Posted: Mon May 19, 2008 6:13 pm |
Thanks, that is a bit nicer. But it seems it has to be ~"%db(@{@nick}, something)~"
-Rappy |
|
_________________ Windows 11 Pro,
cMUD 3.34 |
|
|
|
|
|