Register to post in forums, or Log in to your existing account
 

Play RetroMUD
Post new topic  Reply to topic     Home » Forums » zMUD General Discussion
Atreides_096
Wanderer


Joined: 21 Jan 2005
Posts: 99
Location: Solvang, CA

PostPosted: Tue Apr 19, 2005 1:57 am   

Finding repeat variables
 
I am an old school player, from the TinTin++ days, and as such many of my scripts are written more in the Tintin++ parts of ZMud language than the perl based parts.

I do of course utilize many of the newer comamnds, especially classing, but to most my scripts would look somewhat primitive. One of the biggest things I do with my scripts is to keep everything within their classes for many reasons (organization, easy exportation, easy repair, etc). This includes variables. When a variable is written in a script, it might look like:

Code:
#CLASS {Expratio}
#var fakevar {valuehere}
#CLASS 0

This works fine 99% of the time, but on occasions I have one major problem. For some reason, variables will sometimes write themselves into the wrong class folder. This causes some obvious problems: variables get double written, and/or scripts act on the wrong occurance of a variable (and thus wrong value). This happens most commonly (9 out of 10 times) with 1 specific class folder (Expratio). I've checked and re-checked that script (and every other that has been affected by this issue) and am positive I have put #class 0's everywhere applicable. My theory is that this problem is causes by multiple scripts operating at the same time, with some internal lag or memory leaks causing the actions of multiple scripts to go out of order (thus one script opens a class folder, another write a variable, closes the class folder, and the first script then writes it's variable in the wrong place as well).

So my question here is twofold:

I realize I can rewrite all my scripts (which is a major undertaking, as I currently have 2800+ triggers) to change any occurances of variable UPDATES to "variable=value" -- this doesn't eliminate all instances tho, as often there's #math or %eval functions, or simply the writing of a brand new variable. I don't think it will solve my problem...

1) Outside of the aforementioned change in how to write variables, can anyone think of a better way to write/update my variables to ensure they stay in the proper locations?

2) Barring a good answer to number 1, can anyone think of a simple way (alias) to skim my variables (appx. 600-650 atm) and see if there are any double (or more) occurances of any given variable? Some alias which I could type, for example, "checkdvar" and it would return a listing only of variables that have 2 or more of the same name?

Thanks a lot for your time.. sorry for the long initial explanation, but thought it might be necessary knowledge if there's a viable solution.
Reply with quote
Kiasyn
Apprentice


Joined: 05 Dec 2004
Posts: 196
Location: New Zealand

PostPosted: Tue Apr 19, 2005 2:15 am   
 
I use database keys to collectively store data like...

ch.name = "Kiasyn"
ch.level = 300

etc, that helps make things more "unique"
_________________
Kiasyn
Owner of Legends of Drazon
Coder on Dark Legacy
Check out Talon, an easy IMC connection.
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Apr 19, 2005 4:00 am   
 
Use direct refrencing it is a little bit better but still not the best

#VAR Expratio/fakevar {value}
or
Expratio/fakevar=1


Using #CLASS in a script to change the active folder can be a bad Idea heres why
We have a prompt trigger that adds to the var PROMPT which is in the PROMPT class
However if our script is in the Expratio class before a #CLASS 0 and the prompt comes up we will have a PROMPT var in the expratio class folder also which is not what we want

The best way to CREATE variables is the long way
#VAR name {value} {default val} "classname"
#VAR name {value} {} "classname" //for no default value
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Tue Apr 19, 2005 4:50 am   
 
Quote:

1) Outside of the aforementioned change in how to write variables, can anyone think of a better way to write/update my variables to ensure they stay in the proper locations?


Use the full #VARIABLE syntax:

#VARIABLE name {current value} {default value} "class"

While it won't solve the timing issue, I believe since you tell ZMud where the find the variable it doesn't just give up when it can't find that location and create a new variable in the default class (usually NONE). Also, when you specify names, if you have more than one variable by the same name you can use a special syntax to include the class that variable is found in. I don't use this myself, but it looks something like this:

#variable skills\survival\hungry 1

This will tell ZMud to use the @hungry variable located in the skills|survival folder.

Another thing you might want to look at if you don't do this already is to keep as many of your classes disabled as possible. The more classes you have enabled, the more places ZMud has to look to make sure all available triggers are matched and executed whenever necessary. 2800+ triggers is going to be a HUGE drain your your memory, as all 2800+ will be getting compared to every line coming from the mud. Also, all those buttons and such take up memory so why let them if you're not using them?

Quote:

2) Barring a good answer to number 1, can anyone think of a simple way (alias) to skim my variables (appx. 600-650 atm) and see if there are any double (or more) occurances of any given variable? Some alias which I could type, for example, "checkdvar" and it would return a listing only of variables that have 2 or more of the same name?


There's no viable solution to this problem. The only way to get a list of variables is by using the #VARIABLE command without any parameters and all it does is read from memory and NOT the settings file itself. As such, it doesn't tell you where to find any of your variables AND it also lists variables that are inaccessible (ie, in a disabled class folder.) Since you can't determine where the variables are, you cannot then enable the appropriate folder to delete the duplicate variable.
_________________
EDIT: I didn't like my old signature
Reply with quote
Atreides_096
Wanderer


Joined: 21 Jan 2005
Posts: 99
Location: Solvang, CA

PostPosted: Tue Apr 19, 2005 7:04 am   
 
Thanks for the replies guys. I knew you could write the variables in the format of #var var {val} {d-val} {class} -- I just (sadly) never thought of using that format inside my scripts. I generally use it for prompt entry. I plan to rewrite most of my scripts to that style.

That'll be a big undertaking (editing of 2000+ triggers probably). I'm still hoping someone might have a better option...

In regards to the searching of duplicated variables. I did know of course about the #var listing... And locating the variables is really not that hard. By clicking all classes in the ZMud edit window, then finding the correct variable, it will tell you the path. What I was hoping for is an alias similar to this one:
Code:
 #loop %session.NumAliases {#if %match(%session.AliasNum(%i).Name,%1) { #echo %session.AliasNum(%i).Name} }

That alias was written for me by someone on here, and it does a search for specific aliases. It requires insput to search for though, so can't be readily converted to what I need... It's also a little beyond my personal coding abilities. If anyone here has a way to revise that alias to search for duplicated variables (it doesn't matter if the operation is laggy or useage-intense, as it'll only be used when required to fix a problem) I'd greatly appreciate it!
Reply with quote
Kiasyn
Apprentice


Joined: 05 Dec 2004
Posts: 196
Location: New Zealand

PostPosted: Tue Apr 19, 2005 10:15 am   
 
#alias duplicates {
#unvar aliases
#loop %session.NumAliases {#var aliases %additem(%session.AliasNum(%i).Name,@aliases)}
#loopdb %countlist(@aliases) {#if (%val != 1) {#say %val occurances of %key}}
}

worked for me :P
_________________
Kiasyn
Owner of Legends of Drazon
Coder on Dark Legacy
Check out Talon, an easy IMC connection.
Reply with quote
DeathDealer
Adept


Joined: 20 Jul 2004
Posts: 268

PostPosted: Tue Apr 19, 2005 1:54 pm   
 
errr...Nexela says:
#VAR Expratio/fakevar {value}

MattLofton says:
#variable skills\survival\hungry 1

My question is who is right? / or \ ?
_________________
Reply with quote
nexela
Wizard


Joined: 15 Jan 2002
Posts: 1644
Location: USA

PostPosted: Tue Apr 19, 2005 9:06 pm   
 
#VAR Expratio/fakevar {value} is correct
_________________
Zmud Support Library
Zmud Knowledge Base
Reply with quote
Display posts from previous:   
Post new topic   Reply to topic     Home » Forums » zMUD General Discussion 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