Gammon Forum
Entire forum
MUSHclient
Lua
Help -- First real working script that does something a teensy bit useful.
Help -- First real working script that does something a teensy bit useful.
|
It is now over 60 days since the last post. This thread is closed.
  Refresh page
Posted by
| BobTheGreat
(4 posts) bio
|
Date
| Sat 16 Apr 2011 07:55 PM (UTC) |
Message
| So, my script is very simple. It's only 4 lines.
function test_send (name, line, wildcards)
note "Sending to "..%1
SendNoEcho("greet "..%1)
end -- function
I compile it and use the a trigger to match
amd I get this error:
Compile error
World: Aardwolf
Immediate execution
[string "Script file"]:2: unexpected symbol near '..'
Error context in script:
1 : function test_send (name, line, wildcards)
2*: note "Sending to "..%1
3 : SendNoEcho("greet "..%1)
4 : end -- function
Can someone help? I would greatly appreciate all help, and I am a newbie to scripting so I'm probably doing something so wrong its funny to you :)
| top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #1 on Sat 16 Apr 2011 08:09 PM (UTC) Amended on Sat 16 Apr 2011 08:27 PM (UTC) by Twisol
|
Message
| Four things:
1. Note is capitalized. Variables in Lua are case-sensitive.
2. Functions need () around their arguments. The only exceptions are when you're passing a table or a string, and it has to be the only argument.
3. %1 isn't part of the Lua syntax, it's something the trigger (and alias) dialog does. You want to use wildcards[1] (the wildcards table is passed as a parameter to your script function)
[EDIT]: 4. You're mixing normal patterns with regular expressions. Change the * to a (.*?) and make sure 'Regular expression' is checked, or remove the ^ and $ (and the spaces next to them, I assume) and make sure 'Regular expression' is unchecked. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| BobTheGreat
(4 posts) bio
|
Date
| Reply #2 on Sat 16 Apr 2011 10:40 PM (UTC) |
Message
| Thanks a lot! I really don't understand lua fully and I do have a background in programming. I did exactly what you said with the Regular Expression but that didn't seem to work so I used normal patterns.
Twisol said:
Four things:
2. Functions need () around their arguments. The only exceptions are when you're passing a table or a string, and it has to be the only argument.
3. %1 isn't part of the Lua syntax, it's something the trigger (and alias) dialog does. You want to use wildcards[1] (the wildcards table is passed as a parameter to your script function)
That's what I didn't know and again, thanks for the clearing up :) | top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #3 on Sat 16 Apr 2011 10:41 PM (UTC) Amended on Sat 16 Apr 2011 10:42 PM (UTC) by Twisol
|
Message
| Glad to help!
BobTheGreat said: I did exactly what you said with the Regular Expression but that didn't seem to work so I used normal patterns.
Ah, it was probably the space after the ^. If you had removed that too it probably would have worked. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| BobTheGreat
(4 posts) bio
|
Date
| Reply #4 on Sat 16 Apr 2011 10:49 PM (UTC) |
Message
| Hmmm... I'm a little bit confused. Now I get an error:
Compile error
World: Aardwolf
Immediate execution
[string "Script file"]:1: ')' expected near '['
Error context in script:
1*: function test_send (name,line,wildcards[1])
2 : Note "Sending to "..%1
3 : SendNoEcho("greet "..%1)
4 : end -- function
Was I supposed to pass that as the only argument? Was I supposed to use the [1]? I capitalized the Note() this time and it works.
And, what does this mean?
[string "Script file"]:1: ')' expected near '['
That I don't need ()'s?
Thanks,
Bob :-P
| top |
|
Posted by
| Twisol
USA (2,257 posts) bio
|
Date
| Reply #5 on Sat 16 Apr 2011 10:56 PM (UTC) |
Message
| We're hitting the language barrier now. :) You should go read Programming in Lua [1] first, so you can learn Lua's syntax and how it works. Here's the corrected version of your code though:
function test_send(name, line, wildcards)
Note("Sending to " .. wildcards[1])
SendNoEcho("greet " .. wildcards[1])
end
[1] http://www.lua.org/pil/ |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | top |
|
Posted by
| Nick Gammon
Australia (22,975 posts) bio
Forum Administrator |
Date
| Reply #6 on Sat 16 Apr 2011 10:56 PM (UTC) |
Message
| What Twisol was trying to explain was change:
function test_send (name,line,wildcards[1])
Note "Sending to "..%1
SendNoEcho("greet "..%1)
end -- function
to:
function test_send (name,line,wildcards)
Note ("Sending to ".. wildcards[1])
SendNoEcho ("greet ".. wildcards[1])
end -- function
Or, more readably:
function test_send (name,line,wildcards)
local who = wildcards[1]
Note ("Sending to " .. who)
SendNoEcho ("greet " .. who)
end -- function
[EDIT] Ninja'd! Not surprised. ;) |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | top |
|
Posted by
| BobTheGreat
(4 posts) bio
|
Date
| Reply #7 on Sat 16 Apr 2011 11:03 PM (UTC) |
Message
| Thanks Nick and Twisol!! I really appreciate the tiome and help :) | 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.
20,425 views.
It is now over 60 days since the last post. This thread is closed.
  Refresh page
top
Quick links:
MUSHclient.
MUSHclient help.
Forum shortcuts.
Posting templates.
Lua modules.
Lua documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.