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
➜ General
➜ Lua Beginner
It is now over 60 days since the last post. This thread is closed.
Refresh page
Pages: 1 2
Posted by
| AaronM86
(42 posts) Bio
|
Date
| Mon 29 Mar 2010 07:04 PM (UTC) |
Message
| I was wondering if someone could help teach me how to define variables with Lua. Last night I just switched from Jscript to Lua and am trying to read up on tutorials and what not, but am having trouble finding this. I figure if I can get one thing figured out, it'll give a foundation for it in my mind and then I can expand my tinkering from there.
So, for an example, what I'm trying to do here is, I have an alias titled, "fd *". This used to set a variable titled, "fishDirection". I made this variable through the Variable submenu in my World Configuration. It used to work fine with Jscript, but I'm getting errors now.
The following is what I have edited the alias to thus far, trying to apply Lua to it.
<aliases>
<alias
match="fd *"
enabled="y"
expand_variables="y"
send_to="12"
sequence="100"
>
<send>SetVariable ("fishDirection", "%1" )
Note("fishDirection set to '" + "%1.'")
Send("look");</send>
</alias>
</aliases>
| Top |
|
Posted by
| AaronM86
(42 posts) Bio
|
Date
| Reply #1 on Mon 29 Mar 2010 08:45 PM (UTC) |
Message
| I had an idea I wanted to test, wondering if it might work, in Jscript I used to make functions and I could run them by using say Send: eightball(), and that would run the eightball function from my script notepad. Would the same thing work in Lua or is there a different way of writing it? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #2 on Tue 30 Mar 2010 12:17 AM (UTC) |
Message
| Concatenation in Lua is .. rather than +
So it should read:
Note("fishDirection set to " .. "%1")
Although since wildcard strings are substituted you could just do:
Note("fishDirection set to %1")
As for calling the function, yes you can do it that way. Another way is to put "eightball" in the "script" box of the trigger. But I assume your question is for calling maybe different functions here and there. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| AaronM86
(42 posts) Bio
|
Date
| Reply #3 on Tue 30 Mar 2010 12:24 AM (UTC) |
Message
| Excellent :D This was great help and it will surely get me on my way to putting other puzzles together. Thank you for taking your time to help me. | Top |
|
Posted by
| AaronM86
(42 posts) Bio
|
Date
| Reply #4 on Wed 31 Mar 2010 04:59 AM (UTC) Amended on Wed 31 Mar 2010 05:10 AM (UTC) by Nick Gammon
|
Message
| Hello, was wondering if I could get a little assistance with a chat redirector script that I started to have troubles with after I set it to keep evaluating, as I needed to make another "say" trigger recently and couldn't get it to fire unless I had set my plugin's redirector script logging my says orginally to keep evaluating also. The trigger in the plugin looks like this.
<triggers>
<trigger
enabled="y"
keep_evaluating="y"
match="^\((.*)\/(.*)\)\:(.*)$"
omit_from_output="y"
regexp="y"
script="redirect"
sequence="100"
>
<send></send>
</trigger>
<trigger
enabled="y"
keep_evaluating="y"
match="^(.*?) (say|ooc|yell|shout|ghosttalk|tell|newbiechat|war)(.*?)$"
omit_from_output="y"
regexp="y"
script="redirect"
sequence="100"
>
</trigger>
</triggers>
What is happening is, when I send a chat with mixed words in the trigger it will send my message twice. For example:
I type 'guildchat ooc'
(Terkal/[+} Sovereign {+]): ooc
(Terkal/[+} Sovereign {+]): ooc
Above is what is sent to my chatworld, and the double message is sent to all guild members. | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #5 on Wed 31 Mar 2010 05:12 AM (UTC) |
Message
| They both call "redirect" so it sends the stuff twice. Make only one of them call redirect, the other one can call something else. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| AaronM86
(42 posts) Bio
|
Date
| Reply #6 on Wed 31 Mar 2010 05:29 AM (UTC) |
Message
| Hrm, never had that problem anytime before and they were always set to run the same thing, this only started happening when I added the keep evaluating here:
keep_evaluating="y"
match="^(.*?) (say|ooc|yell|shout|ghosttalk|tell|newbiechat|war)(.*?)$"
omit_from_output="y"
Regardless, I went ahead and change it to a different call name for both and it is still having the same results of double sending.
<trigger
enabled="y"
match="^\((.*)\/(.*)\)\:(.*)$"
omit_from_output="y"
regexp="y"
script="redirecty"
sequence="100"
>
That is the change I made to the call of the first one. | Top |
|
Posted by
| AaronM86
(42 posts) Bio
|
Date
| Reply #7 on Wed 31 Mar 2010 05:35 AM (UTC) |
Message
| My problem may lie directly within the script itself, I had to add a redirecty function.
<script>
<![CDATA[
chat_world = "Dark-Legacy Chats"
local first_time = true
function redirect (name, line, wildcards, styles)
local w = GetWorld (chat_world)
if first_time and not w then
local filename = GetInfo (67) .. chat_world .. ".mcl"
Open (filename)
w = GetWorld (chat_world)
if not w then
ColourNote ("white", "red", "Can't open chat world file: " .. filename)
first_time = false
end
end
if w then
for _, v in ipairs (styles) do
w:ColourTell (RGBColourToName (v.textcolour),
RGBColourToName (v.backcolour),
v.text)
end
w:Note ("")
end
end
function redirecty (name, line, wildcards, styles)[
local w = GetWorld (chat_world)
if first_time and not w then
local filename = GetInfo (67) .. chat_world .. ".mcl"
Open (filename)
w = GetWorld (chat_world)
if not w then
ColourNote ("white", "red", "Can't open chat world file: " .. filename)
first_time = false
end
end
if w then
for _, v in ipairs (styles) do
w:ColourTell (RGBColourToName (v.textcolour),
RGBColourToName (v.backcolour),
v.text)
end
w:Note ("")
end
end
]]>
</script> | Top |
|
Posted by
| AaronM86
(42 posts) Bio
|
Date
| Reply #8 on Wed 31 Mar 2010 05:37 AM (UTC) |
Message
| function redirecty (name, line, wildcards, styles)[
I removed "[" and got it to load right, typo error on my part. But it's still doing the double send, hrm *ponder*... | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #9 on Wed 31 Mar 2010 09:34 AM (UTC) |
Message
|
AaronM86 said:
Hrm, never had that problem anytime before and they were always set to run the same thing, this only started happening when I added the keep evaluating here:
Well previously, only one trigger fired. Now two fire and they both call the same function so it does its stuff twice. |
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| AaronM86
(42 posts) Bio
|
Date
| Reply #10 on Wed 31 Mar 2010 06:30 PM (UTC) |
Message
| Hello, I've converted all my old jscript into lua and organized all my triggers into one file, organized by group name. Made an alias to turn off entire group names at a time, works very efficiently! :D One question I was wondering about, however:
<triggers>
<trigger
enabled="y"
expand_variables="y"
group="Looting"
match=" *an ancient tome of knowledge*"
send_to="12"
sequence="100"
>
<send> world.Send("get all.tome @trapp")
if string.lower("%2") == "1" then
world.Send("exam tome")
elseif string.lower("%2") == "2" then
world.Send("exam tome")
world.Send("exam tome")
end</send>
</trigger>
</triggers>
Will using @trapp in the world.Send still fire the variable correctly in this circumstance? | Top |
|
Posted by
| Nick Gammon
Australia (23,133 posts) Bio
Forum Administrator |
Date
| Reply #11 on Thu 01 Apr 2010 05:03 AM (UTC) |
Message
| Yes but I don't understand why you are doing this:
if string.lower("%2") == "1" then
The number 1 doesn't have an upper and lower-case version, so changing the case doesn't achieve anything.
|
- Nick Gammon
www.gammon.com.au, www.mushclient.com | Top |
|
Posted by
| Twisol
USA (2,257 posts) Bio
|
Date
| Reply #12 on Thu 01 Apr 2010 07:13 AM (UTC) Amended on Thu 01 Apr 2010 07:14 AM (UTC) by Twisol
|
Message
| I told him to use it in an earlier topic (where case was important), and he probably just modified what he knew worked. It's how you learn! :) But yeah, Nick's right. 1 has only one "case", so you shouldn't have to lowercase anything you're comparing against it. |
'Soludra' on Achaea
Blog: http://jonathan.com/
GitHub: http://github.com/Twisol | Top |
|
Posted by
| AaronM86
(42 posts) Bio
|
Date
| Reply #13 on Thu 01 Apr 2010 12:51 PM (UTC) |
Message
| Nod, Twisol, that is the case. Without using the string check, just to confirm, would I write it like this:
if("%2") == "1" then
Thank you both again, especially for your time and patience; you have been loads of support.
| Top |
|
Posted by
| AaronM86
(42 posts) Bio
|
Date
| Reply #14 on Thu 01 Apr 2010 01:33 PM (UTC) |
Message
| Hello and good morning :)
Was hoping to get a little assistance, I've been searching through the list of functions to try and piece this all together. My goal is to have an alias that will Note a list to the world of all my triggers, by group name, that are enabled/disabled. Have one note for all that trigger groups that are enabled and another note for all that are disabled.
I've narrowed it down, to guessing, that I have to use some sort of combination of:
tl = GetTriggerList()
if tl then
for k, v in ipairs (tl) do
Note (v)
end -- for
end -- if we have any triggers
/
Note (GetTriggerOption ("mytrigger", "match"))
"group": (string - group name)
"enabled": y/n - trigger is enabled
/
Note (GetTriggerInfo ("monster", 2))
8: Enabled (boolean)
26: Group name (string)
Those are just copy/pastes of the function examples from the website here. Am I on the right track with guessing these are the functions I would have to use to accomplish my goal?
| 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.
47,375 views.
This is page 1, subject is 2 pages long: 1 2
It is now over 60 days since the last post. This thread is closed.
Refresh page
top