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

Gammon Forum

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

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  General
. . -> [Subject]  Lua Beginner
Home  |  Users  |  Search  |  FAQ
Username:
Register forum user name
Password:
Forgotten password?

Lua Beginner

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Pages: 1 2  

Posted by AaronM86   (42 posts)  [Biography] 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>
[Go to top] top

Posted by AaronM86   (42 posts)  [Biography] 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?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by AaronM86   (42 posts)  [Biography] 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.
[Go to top] top

Posted by AaronM86   (42 posts)  [Biography] 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.
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by AaronM86   (42 posts)  [Biography] 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.
[Go to top] top

Posted by AaronM86   (42 posts)  [Biography] 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>
[Go to top] top

Posted by AaronM86   (42 posts)  [Biography] 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*...
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by AaronM86   (42 posts)  [Biography] 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?
[Go to top] top

Posted by Nick Gammon   Australia  (21,322 posts)  [Biography] 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
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] 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
[Go to top] top

Posted by AaronM86   (42 posts)  [Biography] 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.


[Go to top] top

Posted by AaronM86   (42 posts)  [Biography] 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?


[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.


9,790 views.

This is page 1, subject is 2 pages long: 1 2  [Next page]

It is now over 60 days since the last post. This thread is closed.     [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.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

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

[Best viewed with any browser - 2K]    [Hosted at FutureQuest]