Lesson: #CLASS
[Updated: 5/18/2017]
#CLASS command
#CLASS [class name] [state|options]
The #CLASS command is going to be the basic framework for writing your scripts in zMUD. Classes are used like folders to group triggers, alias, and variables of your script together.
Format:
#CLASS {NAME}
<script>
#CLASS 0
Whenever you use the #CLASS command you are essentially setting that class as the current default class. Make sure to always add the #CLASS 0 as shown in the examples to ensure the default class is reset.
Inside the following example I show how I group my script components inside of a #CLASS:
#CLASS {Example}
#ALIAS exampleAlias1 {}
#ALIAS exampleAlias2 {}
#ALIAS exampleAlias3 {}
#ALIAS exampleAlias4 {}
#VAR exampleVariable1 {}
#VAR exampleVariable2 {}
#VAR exampleVariable3 {}
#VAR exampleVariable4 {}
#VAR exampleVariable5 {}
#VAR exampleVariable6 {}
#TRIGGER "exampleTrigger1" {} {} "" {}
#TRIGGER "exampleTrigger2" {} {} "" {}
#CLASS 0
Since zScript is a language that does not support code comments very well and it is helpful to keep some kind of structure for readability. I like to have all of my #ALIAS at the top, my #VAR in the middle, and my #TRIGGER at the bottom. The zMUD editor follows this formatting also.
#CLASS options: There are two class options that I use regularly and would like to give some insight on {disable} and {enable}.
To set a class option place it inside of brackets after the name of the #CLASS.
#CLASS {Example} {disable}
<script>
#CLASS 0
One other useful command that is used with classes is the #T+ {setting name} and #T- {setting name}. These two commands turn classes, triggers, and most all settings on (#T+) and off (#T-) similar to the class options described below: {disable} and {enable}. The difference is that #T+ and #T- can be used inside your scripts to turn things on and off at will, where the {disable} and {enable} settings turn class folders on and off when you first connect to the mud. To turn the above example class on and off you would write the commands like this: #T+ {example} to enable the class "example" or #T- {example} to disable the class "example".
The disable option is used for whenever you want a class to be turned off when zMUD connects to the mud. When a class is turned off (disabled) zMUD will not use any alias, variables, or triggers inside that class. It is essentially invisible to zMUD.
The enable option is just the opposite of the disable option, it turns the #CLASS on (enabled) when you connect to the mud. This class option will ensure the #CLASS is always enabled when you start your session in case you turned it off (disabled it) at some point during the last session.
Another reason to turn something off (disable) is resource related, zMUD can get bogged down and lag if too many triggers are trying to pattern match on every line from the mud. By writing your scripts so that the majority of your triggers are turned off and only turned on right before you need them (then turned off again) this will help maintain performance. We will go more into this with the upcoming #TRIGGER lesson.
EDIT- I stopped using the {setdef} option as it was creating too many duplicate variables inside multiple places when triggers in different {setdef} classes fired too close to each other. Another way to ensure your variables get saved in the correct place is through explicitly telling zMUD in the variable options where it should go. More of this in the upcoming #VAR lesson.