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
veek
Beginner


Joined: 28 Sep 2006
Posts: 21

PostPosted: Tue Nov 14, 2006 3:46 am   

zMUD equivalent of a C/Perl Function.
 
I am trying to write a re-useable chunk off code in zMUD that is self-contained. In Perl i'd do something like this:

sub FatalError( $ ) {
print STDERR "$progname: @_\n";
exit(1);
}


in zMUD i'd like to do something like this:

#FUNCTION HealWiggly {
#VAR wigglyLocation 0
#VAR tellWiggly {"tell Wiggly Where are You?"}
#REGEX "getWigglyLocation" {^Father Wiggly tells you: I am at (.+)$} {#COLOR Blue; wigglyLocation = %1;}

#SEND @tellWiggly;
}


This does not work. Why? How do i call it from command line and a ALIAS/TRIGGER. #CALL HealWiggly;does not work. Please point me to the relevant documentation.


Also, is there a char that i can use to split a long line of code into multiple lines, like so:

#REGEX "getWigglyLocation" \
{^Father Wiggly tells you: I am at (.+)$} {#COLOR Blue; wigglyLocation = %1;}

Where the \ starts a new line. Or can i just insert a newline and continue on the next line?

I tried something with #CLASS like so.

#CLASS {HealWiggly}
#VAR wigglyLocation 0
#VAR tellWiggly {"tell Wiggly Where are You?"}
#REGEX "getWigglyLocation" {^Father Wiggly tells you: I am at (.+)$} {#COLOR Blue; wigglyLocation = %1;}

#SEND @tellWiggly;
#CLASS 0

But the #REGEX line keeps disappearing. Also i can't seem to be able to do #SEND from within a CLASS.
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Tue Nov 14, 2006 11:20 am   
 
What you are looking for is an #ALIAS. Most commonly you would create the #REGEX trigger outside of the alias, and then enable and disable it for minor speed gains or spoof resistance.

#CLASS WigglyStuff
#VAR wigglyLocation {} {}
#REGEX "getWigglyLocation" {^Father Wiggly tells you: I am at (.+)$} {#COLOR Blue;#VAR wigglyLocation {%1}}
#ALIAS HealWiggly {#SEND "tell Wiggly Where are you?"}
#CLASS 0
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
veek
Beginner


Joined: 28 Sep 2006
Posts: 21

PostPosted: Wed Nov 15, 2006 2:27 am   
 
Thanks, the code is looking reasonably pretty. Is the context in which variables exist explained anywhere - Variable scope when used within a CLASS, FUNCTION, TRIGGER, ALIAS? Also, about #REGEX.. within a ALIAS it is created only when the ALIAS is called? In a CLASS, is it created only when i enter the context of that CLASS?
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Wed Nov 15, 2006 3:30 am   
 
There is no scope in ZMud but there are rules that are followed:

1)Is a path specified (@../Var1)

2)check the default class (this is set by the #CLASS command, with #CLASS 0 returning the default back to the root class)

3)starting with the root class, check for first-found. Enter subfolders and subfolders of the subfolders before moving on to the next peer:

Code:

NONE
|
|
---Class1
|       |
|       |
|       ---Class2
|               |
|               |
|               ---Class5
|               |
|               |
|               ---Class4
|
|
---Class3


In the above diagram, the order of search would be NONE, Class1, Class2, Class5, Class4, and finally Class3.
_________________
EDIT: I didn't like my old signature
Reply with quote
veek
Beginner


Joined: 28 Sep 2006
Posts: 21

PostPosted: Wed Nov 15, 2006 3:19 pm   
 
Thanks for the Help Matt, but what i meant was like so:

#CLASS {Blah}
#VAR MyVar 5

#TRIGGER {^.+$} {#VAR MyVar 10}
#TRIGGER {^.+$} {/Blah/MyVar abcd} ; Which variable is being altered?
#REGEX {^.+$} {#VAR MyVar 20}
#ALIAS boo {#VAR MyVar 30}
#CLASS 0

Now, physically in memory is there like 4 different var's all called MyVar, or is there some other combination of MyVar's. Within a CLASS, how do the elements interact..as in..does the TRIGGER become active only when i switch context to that CLASS or is it active the moment i Import my cfg file. This stuff should be documented somewhere but i can't find it! GRR! It's drving me nuts since i have to sit and research zMUD and delay scripting and the docs have got heaps of verbiage without explaning basic scripting and the zMUD language properly! I mean look at how the Perl/Bash man pages are! *sigh* Mind you i do like zMUD for it's features but the lack of decent docs explaning basics is very irritating..the docs are a mish-mash of tutorials-for-the-noob to get him up and running, they don't really explain anything beyond very basic usage - at least the VAR/CLASS bit. Of cousrse if i've actually missed the section which contained the info then i apologise in advance!
Reply with quote
Vijilante
SubAdmin


Joined: 18 Nov 2001
Posts: 5182

PostPosted: Wed Nov 15, 2006 11:20 pm   
 
Actually most of the tutorial sections of the help is written for the "noob". That is why it doesn't explain stuff in programmerese, and is excessively verbose. The reference sections of the help are more meant for programmers that have a concept of how things work, and attempt to include some cross-language referencing so a programmer that is knowledgable in another language can readily find the right function or command in zMud. Discussions about 'scope' and such are pretty much left out.

In it is rather plain to me that your your a trained programmer, versed in current methods and fashions. zMud started back in the early-mid 90's and its language of zScript has grown and developed from there. Scope wasn't an issue then, and threads hadn't even been born yet. zScript has grown quite organically from those roots and still has little to no concept of scope, in fact duplicate names for settings only started to be handled a few versions ago. There really is no reason for duplication of major variable names beyond programmers are lazy.

I have been saying that programmers are lazy for many years, and I happen to have the experience to back it up since I started programming on Apple IIc's in the early 80's. zScript is more of an old school language, and it is far easier to create distinct variables for seperate portions of your script then it is to actually implement scoping in it.

I would suggest that if you wish to see more language features of that type you should consider moving to CMud and starting your learning there.
_________________
The only good questions are the ones we have never answered before.
Search the Forums
Reply with quote
MattLofton
GURU


Joined: 23 Dec 2000
Posts: 4834
Location: USA

PostPosted: Thu Nov 16, 2006 12:16 am   
 
To answer your question, Veek, assuming there are no other @MyVar variables contained in other classes, you actually only have one @MyVar variable. The second #TRIGGER's #VAR syntax (where your question is) is simply a more specific way to name the variable you want to edit.

Now, given the way triggers and aliases and so on work, it's possible (not likely, just possible) that the #VAR commands in the first #TRIGGER, regex, and alias may be created elsewhere. This can happen, for instance, if Blah were to be disabled and a #VAR reference to MyVar were made outside of that class.
_________________
EDIT: I didn't like my old signature
Reply with quote
veek
Beginner


Joined: 28 Sep 2006
Posts: 21

PostPosted: Fri Nov 17, 2006 8:09 am   
 
Thanks guys! Umm, actually i'm just a noob programmer in college etc and not even in Comp Sci, so maybe that's why i found it confusing..anyway thank you. It's clear now!! And i do appreciate all the help! Hopefully i won't bug you guys for the next few months :)
Reply with quote
Seb
Wizard


Joined: 14 Aug 2004
Posts: 1269

PostPosted: Fri Nov 17, 2006 11:28 pm   
 
There are also some articles for advanced stuff in the Support, zMUD Support area from the menu at the top of this page.
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