Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are
spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the
password reset link.
Due to spam on this forum, all posts now need moderator approval.
Entire forum
➜ MUSHclient
➜ Lua
➜ New to MUSHclient Lua Scripting
New to MUSHclient Lua Scripting
|
It is now over 60 days since the last post. This thread is closed.
Refresh page
Posted by
| Silentius
(16 posts) Bio
|
Date
| Sat 01 Mar 2008 07:45 PM (UTC) |
Message
| Ok, so after browsing around for a while.. I felt ready to try and set up my own script. I loaded up mushclient... connected to the world... created a new trigger...
Put in
BLahh * more blaaahh * blah.
Then went down to Scripts and put in
MyScript
I then went to the scripts, made a blank lua file and put in:
Sub Myscript (name, trig_line, wildcards)
local mobname = wildcards [1]
local experience = wildcards [2]
Say("That was a " .. mobname)
Say("I got " .. experience)
end -- of Myscript
After that I saved it. However.. when I try to test the trigger to see if it all works, I get the following error...
[string "Script file"]:1: '=' expected near 'Myscript'
Any tips?
| Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #1 on Sat 01 Mar 2008 08:08 PM (UTC) |
Message
| Have a look inside exampscript.lua which comes with MUSHclient. The examples there should help.
For a start, you declare functions with "function" not "Sub" (Sub is from VBscript). So the first line should read:
function Myscript (name, trig_line, wildcards)
Then these lines use a function that doesn't exist:
Say("That was a " .. mobname)
Say("I got " .. experience)
You need to "Send" the "say" command, like this:
Send ("say That was a " .. mobname)
Send ("say I got " .. experience)
Or if you meant to say it to yourself, use Note, like this:
Note ("That was a " .. mobname)
Note ("I got " .. experience)
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Silentius
(16 posts) Bio
|
Date
| Reply #2 on Sat 01 Mar 2008 08:15 PM (UTC) Amended on Sat 01 Mar 2008 08:40 PM (UTC) by Silentius
|
Message
| [string "Script file"]:6: attempt to call global 'Say' (a nil value)
stack traceback:
[string "Script file"]:6: in function <[string "Script file"]:1>
Called By:
Function/Sub: Myscript called by trigger
Reason: processing trigger ""
(Once I get one simple script working, I will be able to do the rest.) | Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #3 on Sat 01 Mar 2008 08:38 PM (UTC) |
Message
| Did you read the rest of my reply? There is no MUSHclient command "Say" - you need to use "Note". |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Silentius
(16 posts) Bio
|
Date
| Reply #4 on Sat 01 Mar 2008 08:41 PM (UTC) |
Message
| Ahh, I'm all hopped up on Limeade. Sorry :) | Top |
|
Posted by
| Silentius
(16 posts) Bio
|
Date
| Reply #5 on Sat 01 Mar 2008 08:48 PM (UTC) |
Message
| <triggers>
<trigger
enabled="y"
group="Multi Line"
lines_to_match="2"
keep_evaluating="y"
match="(.*?) is DEAD\!\nYou receive (.*?) combat experience\.\Z"
multi_line="y"
regexp="y"
script="Myscript"
sequence="100"
>
<send>%0</send>
</trigger>
</triggers>
I'm getting calls to the script, but It's not sending back the responses... I recoded the lua to be
function Myscript (name, trig_line, wildcards)
local mobname = wildcards [1]
local experience = wildcards [2]
Send ("say That was a " .. mobname)
Send ("say I got " .. experience)
end -- of Myscript
| Top |
|
Posted by
| Nick Gammon
Australia (23,162 posts) Bio
Forum Administrator |
Date
| Reply #6 on Sat 01 Mar 2008 09:40 PM (UTC) |
Message
| Well it worked when I tested it.
One thing to look out for is, after a script error, it disables calling that script function again, so you don't get the same error message many times.
You need to go to the Game menu -> Reload Script File. This forces the file to be reprocessed and clears any script errors for triggers.
I would also not put %0 in the "send" box as that is sending the matching line back to the MUD. Just leave it blank.
An alternative approach, which might be simpler, is to use "send to script" rather than using a script file. In this case you leave the "script" box blank, and put scripting commands directly in the trigger, like this:
<triggers>
<trigger
enabled="y"
group="Multi Line"
lines_to_match="2"
keep_evaluating="y"
match="(.*?) is DEAD\!\nYou receive (.*?) combat experience\.\Z"
multi_line="y"
regexp="y"
send_to="12"
sequence="100"
>
<send>
local mobname = "%1"
local experience = %2
Send ("say That was a " .. mobname)
Send ("say I got " .. experience)
</send>
</trigger>
</triggers>
Now the wildcards are just %1, %2 etc. inside the Send box. Note that you have to quote string wildcards (like a mob name).
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Silentius
(16 posts) Bio
|
Date
| Reply #7 on Sat 01 Mar 2008 10:30 PM (UTC) Amended on Sun 02 Mar 2008 02:15 AM (UTC) by Silentius
|
Message
| awesome. Thanks for the help. Now that I figured out how to make it work, I've already added on the ability to figure out when my exp gain drops, and move onto the next tier of enemies :) | Top |
|
The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).
To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.
21,063 views.
It is now over 60 days since the last post. This thread is closed.
Refresh page
top