[Home] [Downloads] [Search] [Help/forum]

Gammon Software Solutions forum

See www.mushclient.com/spam for dealing with forum spam. Please read the MUSHclient FAQ!

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Help -- First real working script that does something a teensy bit useful.
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

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.   [New subject]  Start a new subject   [Refresh] Refresh page


Posted by BobTheGreat   (4 posts)  [Biography] bio
Date Sat 16 Apr 2011 07:55 PM (UTC)  quote  ]
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

^ * tells you 'sup'$


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 :)
[Go to top] top

Posted by Twisol   USA  (2,230 posts)  [Biography] bio
Date Reply #1 on Sat 16 Apr 2011 08:09 PM (UTC)  quote  ]

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
[Go to top] top

Posted by BobTheGreat   (4 posts)  [Biography] bio
Date Reply #2 on Sat 16 Apr 2011 10:40 PM (UTC)  quote  ]
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 :)
[Go to top] top

Posted by Twisol   USA  (2,230 posts)  [Biography] bio
Date Reply #3 on Sat 16 Apr 2011 10:41 PM (UTC)  quote  ]

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
[Go to top] top

Posted by BobTheGreat   (4 posts)  [Biography] bio
Date Reply #4 on Sat 16 Apr 2011 10:49 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Twisol   USA  (2,230 posts)  [Biography] bio
Date Reply #5 on Sat 16 Apr 2011 10:56 PM (UTC)  quote  ]
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
[Go to top] top

Posted by Nick Gammon   Australia  (19,534 posts)  [Biography] bio   Forum Administrator
Date Reply #6 on Sat 16 Apr 2011 10:56 PM (UTC)  quote  ]
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
[Go to top] top

Posted by BobTheGreat   (4 posts)  [Biography] bio
Date Reply #7 on Sat 16 Apr 2011 11:03 PM (UTC)  quote  ]
Message
Thanks Nick and Twisol!! I really appreciate the tiome and help :)
[Go to top] 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.


2,886 views.

It is now over 60 days since the last post. This thread is closed.   [New subject]  Start a new subject   [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

[Home]

Written by Nick Gammon - 5K

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( http://www.gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Web site powered by FutureQuest.Net]