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.
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?
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.
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.
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:
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 ("")
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.
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?
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.
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?
Yes you are on the right track. Combined with a bit of table handling. This should do it:
<aliases>
<alias
match="show_groups"
enabled="y"
send_to="12"
sequence="100"
>
<send>
local tl = GetTriggerList()
if not tl then
print "No triggers"
return
end -- if
local groups = {}
-- work out which ones enabled
for k, v in ipairs (tl) do
local group = GetTriggerOption (v, "group")
-- create table entry for this group first time around
groups [group] = groups [group] or { enabled = 0, disabled = 0 }
if GetTriggerOption (v, "enabled") == 1 then
groups [group].enabled = groups [group].enabled + 1
else
groups [group].disabled = groups [group].disabled + 1
end -- if
end -- for
-- show results, per group
for k, v in pairs (groups) do
ColourTell ("white", "", string.format ("%%15s: ", k))
if v.enabled > 0 then
ColourTell ("green", "", string.format ("%%i enabled ", v.enabled))
end -- if
if v.disabled > 0 then
ColourTell ("yellow", "", string.format ("%%i disabled ", v.disabled))
end -- if
Note "" -- new line
end -- for
</send>
</alias>
</aliases>
For advice on how to copy the above, and paste it into MUSHclient, please see Pasting XML.
A whole group is not necessarily enabled (so this alias shows, per group, how many in that group are enabled and how many disabled).
Ah, excellent! I had attempted to set this up all morning lol, kept running into a bit of trouble. I see what I was doing wrong now. Thanks :D Appreciate it a ton.