![](templates/Classic/images/spacer.gif) |
kjaerhus Magician
![](images/avatars/1421627674bb6034d66b33.png)
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Sun Jan 20, 2008 1:28 am
[2.18] Strange bug when referring to variable in other class |
I have two characters on the same mud and want to use same scripts for those. This means that I have to do a little work every time a certain action depends on the character I am currently using. So if I for instance want to refer to my shield I have to find out in my script which characters shield we are talking about.
Ok, so I have a trigger when I enter the mud where I use the %gsl function to get the name of the character logged in from the mud. This works fine and I put the name in a variable called characterName. Triggers content is:
/Capturing/GSL/characterName = %delete(%gsl(B), 1, 10)
The deleting is because there is 10 characters of rubbish before the name when getting B. Ok, so in my Armor class I have made two classes named after my characters. In both of these classes I have a variable called @shield which holds the name of the shield. Then I have made an alias that is supposed to tell me the name of the shield of the character currently logged in. The content of this alias is shown below:
$class = "/Equipment/Armor/"
$character = @/Capturing/GSL/characterName
$item = "/shield"
#SAY Shield $class$character$item: @{$class$character$item}
Ok, so what is really strange to me here is that although the characterName variable seems to hold the right name, but when I look at the output of my alias I may see the name and shield of my OTHER character. I have no idea where it gets this value from. Se example output below: (names are changed to xxx and yyy)
Shield /Equipment/Armor/xxx/shield: xxxShield
(but charactername that should be referenced is yyy)
Any ideas? |
|
|
![](templates/Classic/images/spacer.gif) |
kjaerhus Magician
![](images/avatars/1421627674bb6034d66b33.png)
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Sun Jan 20, 2008 4:27 pm |
Another annoying thing I experience right now is that if you have two different aliases with the same name but in two different classes I cannot be sure which one the engine chooses to run even though the name is fully qualified. Example:
$characterName = @getGSLCharacterName()
$shield = @{"/Equipment/Armor/"$characterName"/shield"}
#EXEC "/Equipment/Armor/"$characterName"/removeMyShield" $shield
Now, if I use #SAY instead of #EXEC if see the path (name changed to xxx):
/Equipment/Armor/xxx/removeMyShield xxxShield
...and there IS indeed an alias called "removeMyShield" in this class. However an alias with the same name is in another class called yyy and this is the alias that gets to be called. This is not changing so if it's wrong the first time I try it will continue to be. So as I see it right now there is no way the have several aliases/variables/etc. with the same name and be sure to get the right one. |
|
|
![](templates/Classic/images/spacer.gif) |
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Sun Jan 20, 2008 5:40 pm |
#class Equipment|Armour|xxx
removeMyShield xxxshield
#class 0
Edit: Or not...
Where alias Test exists in class one and in class two.
#T+ class1/Test Alias
#T- class2/Test Alias
test
#T- class1/Test Alias
#T+ class2/Test Alias
test
Does not work properly, only one or the other will work at all even if you issue the commands repeatedly.
The same goes for just enabling or disabling a class... An alias sticks with whatever test alias was first or enabled when it was compiled. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram
Last edited by Arminas on Sun Jan 20, 2008 6:03 pm; edited 1 time in total |
|
|
![](templates/Classic/images/spacer.gif) |
kjaerhus Magician
![](images/avatars/1421627674bb6034d66b33.png)
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Sun Jan 20, 2008 5:57 pm |
Is that the way to do it? What's wrong with the other way? And why the |'s?
|
|
|
![](templates/Classic/images/spacer.gif) |
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Sun Jan 20, 2008 6:09 pm |
Actually that should be one of the ways to do it. It isn't working if you look up at my edit. The other two ways are not working either.
Regardless having two aliases by the same name is not the preferred way to do this sort of thing.
$characterName = @getGSLCharacterName()
With all of the complex things you have going on it looks like you could simply use a character name check and substitute what you are sending to your window based on that within a single alias...
I can't get specific because based on the round about way you are doing things I cannot predict what the rest of your setup looks like. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
![](templates/Classic/images/spacer.gif) |
Fang Xianfu GURU
![](images/avatars/1763170544a2093e7e85da.gif)
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jan 20, 2008 6:16 pm |
The way that's generally advised to do this is to use a separate session icon for each character. Then create separate modules in each session's package for character-specific aliases to go in. As long as the module is local, they won't interfere with each other. If the logic of the aliases is the same but the character names differ, you can use a single package with the Shared option turned off - that means that each session will load its own version of the package, which then won't interfere with the versions loaded by other sessions.
|
|
|
![](templates/Classic/images/spacer.gif) |
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Sun Jan 20, 2008 6:21 pm |
Edit : Ninja'd by Fang...
If you still wanted to only use a single session..
An example would be to have a database variable that contains all of the names of the characters that you play with that settings file.
Then you have the equipment they are using within the subset of their name. Have a look at my HashSet post in the general forum. I used a little girl and a little boys clothing as examples. Use the package from the package library if you decide to use this suggestion...
Anyway you could have a variable that holds the name of the Current player and just do actions in your aliases based on that players information.
Variable Players
Values
John = shield=shield12|Hat=hat13
Jake = shield=shield22|Hat=hat23
Variable Current
value Jake
Alias RemoveMyShield
Remove @players.@current.shield
If you enter RemoveMyShield you get
remove shield22 |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
![](templates/Classic/images/spacer.gif) |
kjaerhus Magician
![](images/avatars/1421627674bb6034d66b33.png)
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Sun Jan 20, 2008 7:54 pm |
I haven't messed much around with modules yet so I can't say if that is the way to go or not. However, the reason why I have made things the way I have is because there is a lot of common variables/trigger/aliases/functions/etc. that can be shared between my two characters but there are of course differences. That is most particular related to equipment, but there may be things the two characters do differently which demands separate aliases. If it was just names I agree it could be relevant to just have maps/db variables.
I think one suggested that I made the check in the aliases, but that not be a nice solution as I would have to edit core scripts when adding a new character. In this way I only need to make a class with the same name as the character and add the exact same variables and aliases as the others to be rolling.
I really can't see why I can't have two aliases or variables with the same name as long as they reside in different classes. I mean, I realize that it gives me problems but I don't really accept that it should be that way. To me it's a bug. I have so many variables and aliases that it can be hard to figure out good names when they have to be unique. If you take the word "class" and relate it to normal programming languages like Java for instance you would expect more than you get now. |
|
|
![](templates/Classic/images/spacer.gif) |
Fang Xianfu GURU
![](images/avatars/1763170544a2093e7e85da.gif)
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Sun Jan 20, 2008 8:12 pm |
The two aren't mutually exclusive. You can have things that both characters use the same in a common (albeit unshared) package while keeping character-specific things (including variables containing character-specific values) in that character's package.
I don't disagree that there's probably a bug here, but with a view to getting it working now, this is the way I'd recommend. |
|
|
![](templates/Classic/images/spacer.gif) |
Arminas Wizard
Joined: 11 Jul 2002 Posts: 1265 Location: USA
|
Posted: Sun Jan 20, 2008 9:47 pm |
I still haven't looked much into the way Fang is suggesting to do this but, it is the closest way that I still haven't tried to what you are trying to do. If it works it would require the least effort to convert your scripts over.
Main session Package -> Contains all of the common aliases/macros/triggers/variables
Char name or class Packages -> contain the classes that you would have been turning on or off using the methods that have failed so far...
All of your variables can remain in the Main session if you like. |
|
_________________ Arminas, The Invisible horseman
Windows 7 Pro 32 bit
AMD 64 X2 2.51 Dual Core, 2 GB of Ram |
|
|
![](templates/Classic/images/spacer.gif) |
kjaerhus Magician
![](images/avatars/1421627674bb6034d66b33.png)
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Mon Jan 21, 2008 5:09 pm |
Not sure how to use these modules. If I try to refer to a variable residing in a module I still get the one with the same name in the same window. When I take a look at the compiled code it say the name of the window too. Can anyone give an example? I thought I could refer to variable a in module x from an alias in window b by writing @x/a. That however seems not to work.
|
|
|
![](templates/Classic/images/spacer.gif) |
Fang Xianfu GURU
![](images/avatars/1763170544a2093e7e85da.gif)
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Jan 21, 2008 5:13 pm |
You're looking for @//x/a but the idea is that you don't need to do that. There should only be one copy of variables whose values are the same for both characters (in the shared package) and there should be one copy for each character of variables with different values, which should be in their individual windows. Then when an alias looks for a value for any particular variable, it'll look in the window for that session before the other window and should always return the right value.
|
|
|
![](templates/Classic/images/spacer.gif) |
kjaerhus Magician
![](images/avatars/1421627674bb6034d66b33.png)
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Mon Jan 21, 2008 6:28 pm |
My thought was to make two modules each named after a character and these modules should contain character specific data. I am not sure what you mean. Maybe it's because I haven't worked with modules before now. Could you give a simple example to show what you mean?
|
|
|
![](templates/Classic/images/spacer.gif) |
Fang Xianfu GURU
![](images/avatars/1763170544a2093e7e85da.gif)
Joined: 26 Jan 2004 Posts: 5155 Location: United Kingdom
|
Posted: Mon Jan 21, 2008 6:46 pm |
MySession1.pkg - This package is created by CMUD automatically when you set up the MySession1 session.
MySession1 - Window - comes with the MySession1 package
MySession1Mod - Module (Global) - put your character-specific stuff for MySession1's character in here including variables
MySession2.pkg - Same as MySession1 but a separate file for a separate character, with slightly different names.
MySharedStuff.pkg - Create this package, set the Shared flag off and add it to the package list for both sessions (On the Sessions dialogue, rclick, edit session, and add it on the Package Files tab, or just open each session individually and open the package file).
MySharedStuff - module - put stuff you want both characters to be able to use in here
And that should hopefully be it. I don't use a setup like this myself, but I've helped people with things like this before - I'm working from memory, so forgive me (and please tell me) if I've done something wrong. |
|
|
![](templates/Classic/images/spacer.gif) |
kjaerhus Magician
![](images/avatars/1421627674bb6034d66b33.png)
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Mon Jan 21, 2008 7:22 pm |
I'll have to make some experiments for a while. Thanks for your help so far. :-)
And Zugg, if you read this I really do want to emphasize that I think it's a bug that I can't have several variables etc. with the same name as long as they belong to different classes. It's not very logical and it does lead to confusion. |
|
|
![](templates/Classic/images/spacer.gif) |
Dumas Enchanter
Joined: 11 Feb 2003 Posts: 511 Location: USA
|
Posted: Tue Jan 22, 2008 5:36 pm |
The problem with using the same variable name over and over is that eventually you get confused, and so can any type of compiler. It isn't a stretch to use a slightly different name, even going as easy as just appending the class name to the front of the variable.
|
|
|
![](templates/Classic/images/spacer.gif) |
kjaerhus Magician
![](images/avatars/1421627674bb6034d66b33.png)
Joined: 18 Dec 2006 Posts: 317 Location: Denmark
|
Posted: Wed Jan 23, 2008 5:47 pm |
Well the things is, Dumas, that even putting the classname in front of the variable is not quite reliable. It seems that if you fully qualify the name all the way from the window/module name variables will be referenced correctly though so @//mywindow/someclass/someotherclass/myvariable should work even if you have other variables with the same name in other classes.
However, I haven't found any way to do the same with aliases so as I see it there is at the moment no way to have two aliases with the same name and be sure that the right one is executed even if you fully qualify the name. And that I do believe is a bug. The variable thing could work better too in my oppinion. |
|
|
![](templates/Classic/images/spacer.gif) |
|
|