IFs and scripting

Posted by Caeser on Sat 09 Jul 2005 02:03 AM — 8 posts, 36,288 views.

#0
Hi I am new to MUSHclient and scripting.
I don't have any scripts done or started for that matter, and was wondering:

How would you go about doing embedded if statements?
Also, how would you go about making a lot of triggers with scripting? I am trying to have a trigger set a variable, and then activate that large IF statement, and then when the IF statement detects the variable, it'll do what I want it to do, and then shut off the variable?

Sorry for asking for help on what I hope is something easy to do.
#1
It's easier to answer questions like this when you provide a concrete example. If you give messages from your game and describe what should happen for that particular scenario, we can give you advice on how to script the client to do just what you want.
#2
Okay, I'll give the examples:
The MUD I play is Achaea, so I am hit with 2 venoms.
Now I can't eat the cure for both at once, since you can only eat 1 herb at a time, so then I have to wait until getting a message saying you can eat another herb.

So I am hit with:
^Hmmmm. Why must everything be so difficult to figure out?$

and

^Your body stiffens rapidly with paralysis.$

The first message I want to set to variable Stupidity and the second to variable Paralysis.

I want to cure the more important one first, so I want to cure the stupidity, and then when I can eat again cure the paralysis. For other MUD clients I have used, this is obtained by use embedded IF statements...but I could never get them to work. If there is another, easier way of doing this (I do have a lot more variables and messages then these 2, but I only picked these two as an example) with MUSHclient? If so or if not, can you explain how I would do this?
Amended on Sat 09 Jul 2005 03:50 PM by Caeser
#3
Also before I forget, how *DO* you start scripting? Can you just do it in a Wordfile? And if you can, can you just save it to the type of file you need?
USA #4
You create a script file just in any old text editor, and just save it as a vbs (since youre using VBScript). Mushclient has an internal notepad which you can use as well. You enable scripting in the script configuration screen (game > config > scripting). Make sure it's set to VBScript, and make sure it's enabled.

The 'new' (although it's been around for a while) way of scripting is to not use a script file. You can embed the script commands straight in the items (trigger/alias/timer) send text (and set the 'sendto' value to script).

You can take a look at all of the script functions (those are things you can call in your script that will do things with mushclient) from the link at the top of the mushclient forum (list of inbuilt script functions).

However, I suggest you take a look at the documentation (the new one, so either download the new help file, or view it online):
http://www.gammon.com.au/scripts/doc.php?general=scripting
it will get you started and explain all the nuances.
#5
Okay, 3 things...
1) That documentation page *REALLY* helped. It cleared up a lot of questions.

2) But, in the documentation it says when I script triggers I need to have 3 arguments: the text to match, the
command(s) it does, and then the wildcards.
I don't quite understand what that means though

3) One more question about the documentation and scripting in general: Why do I need to define error codes in my scripts?

Thanks, knowing what I know now, it'll really help with making the script I want for myself.
Amended on Sat 09 Jul 2005 10:18 PM by Caeser
USA #6
Defining those constants (error codes and flags) aren't really important, Basically, if you look at the bottom of each script function (on the scripting documentation page) it will tell you what it returns (0 is Ok, etc) defining those error codes allows you to check the return against eOk instead of 0 (or whatever they actually are). They aren't necessary, but sometimes can help.

The three arguments (for when you call subroutines in triggers) are Name, Line, and Wildcard, youll see this a lot:
Sub SomeRoutine (sName, sLine, aryWild)
... sub routine here
End Sub

The triggers (and aliases) pass those arguments (the name of the trigger/alias that called the routine, the line it was called from, and then an array of the wildcards that were matched). Timers only send the name (so your subroutine has to be different if being called by a timer).

If you use the built-in scripting (when you put the script in the send box of the trigger/alias) you don't need to worry about that stuff, which is a big plus (you can just use the wildcard match things like %1 %2, and you can get the full like with %0) for normal cases (but if you want to have multiple triggers do the same thing, you have to type them all out). Of course, you could always call a subroutine from the embedded scripts.
Putting the scripts into the triggers themselves makes creating scripts a lot easier, since you dont have to open/edit/save/reload the script file each time you make a change.
#7
Okay, thanks...
Now for my (hopefully) last question for a while:

I want to do one long IF statement, filled with embedded IFs. Now, to call an IF statement that long, do I need to make it a script and have each trigger that sets a variable in the statement activate the script? And if so, how do I activate the script? I am a little unclear as to doing that.