Help -- First real working script that does something a teensy bit useful.

Posted by BobTheGreat on Sat 16 Apr 2011 07:55 PM — 8 posts, 31,547 views.

#0
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 :)
USA #1
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.
Amended on Sat 16 Apr 2011 08:27 PM by Twisol
#2
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 :)
USA #3
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.
Amended on Sat 16 Apr 2011 10:42 PM by Twisol
#4
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
USA #5
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/
Australia Forum Administrator #6
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. ;)
#7
Thanks Nick and Twisol!! I really appreciate the tiome and help :)