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


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Lua
. . -> [Subject]  Newbie question

Newbie question

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


Pages: 1 2  

Posted by Jedhi   (37 posts)  [Biography] bio
Date Thu 22 Sep 2011 05:20 PM (UTC)
Message
Hello,

i have tried everything to make a lua script work with simple one line trigger without any success. can someone please give me an example what i must exectly type into myscript.lua to match "this is a line" and send to the world "say this is a test"

Thank you!
[Go to top] top

Posted by Mm1mark   (24 posts)  [Biography] bio
Date Reply #1 on Thu 22 Sep 2011 05:43 PM (UTC)
Message
why not just give us an example of what your trying to catch. will make it easier for us to help.
are you trying to match chats, hp, targets, mobs.
bob says...
[Go to top] top

Posted by Jedhi   (37 posts)  [Biography] bio
Date Reply #2 on Thu 22 Sep 2011 05:55 PM (UTC)
Message
I'm just trying to get myself started with this scripting thing. just match the line i gave. really doesn't matter cause i can't match anything with scripting
[Go to top] top

Posted by Daniel P   USA  (97 posts)  [Biography] bio
Date Reply #3 on Thu 22 Sep 2011 05:59 PM (UTC)

Amended on Thu 22 Sep 2011 06:13 PM (UTC) by Daniel P

Message

<triggers>

<trigger
 match="this is a line"
 enabled="y"
 regexp="n"
 send_to="12"
 sequence="100"
>
<send>
Send("say this is a test")
</send>
</trigger>

</triggers>


That's your fairly basic TRIGGER trigger. If you wanted to match a line within a script, you could always do something like string.find(), string.match(), string.sub(), etc.

One such script that I just wrote is as follows:


location = "rep12089176"
items = {
  id = "12098735",
  name = "Item Name"
}
if string.match(location,"rep",1) ~= nil then
  Note("Received container contents!!")
  Note("Container number: " .. string.sub(location,4))
  for k, v in pairs(items) do
    Note(v)
  end -- for
end -- if


The string.match(location,"rep",1) returns a numerical position of the first occurrence of the search string "rep" if it exists anywhere in the "location" variable.

The string.sub(location,4) returns the substring in the "location" variable from position 4 onward -> "12089176".

So you COULD do something like string.sub(location,string.match(location,"rep",1))

So in plain English, location is a string variable. Items is a table with two string variables.

If location has the word "rep" anywhere within it, then print the string from the position where "rep" ends onward to the end. Then for every variable in the items table, print the value of it. But only do this if "rep" exists in the location string.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #4 on Thu 22 Sep 2011 10:57 PM (UTC)
Message
Jedhi said:

Hello,

i have tried everything to make a lua script work with simple one line trigger without any success. can someone please give me an example what i must exectly type into myscript.lua to match "this is a line" and send to the world "say this is a test"

Thank you!


You don't need to use myscript.lua at all initially. Just script directly inside triggers as Daniel illustrated.

However if you want to go the trigger/script file route, please paste both your trigger, and your script file.

Template:copying For advice on how to copy aliases, timers or triggers from within MUSHclient, and paste them into a forum message, please see Copying XML.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Jedhi   (37 posts)  [Biography] bio
Date Reply #5 on Fri 23 Sep 2011 12:17 PM (UTC)
Message
Thank you!
Is it possible to chech inside a trigger the room i'm in and then dicide which action to take?
[Go to top] top

Posted by Jedhi   (37 posts)  [Biography] bio
Date Reply #6 on Fri 23 Sep 2011 07:04 PM (UTC)

Amended on Fri 23 Sep 2011 07:32 PM (UTC) by Jedhi

Message
I have tried to figure this mush+lua out.

can someone please point me to right tutorials or something. like where can i find <trigger> <alias> detailid description?

like what do the trigger variables send_to="12" sequence="100" stand for? how can i use custom functions with triggers, how to interact with the mud(aard). for example how to get the rooms id and so on...

like what's the difference between <alias> and AddAlias

AddAlias("test_aliases", "my_test", "gt this is a test", alias_flag.Enabled, "")

is it possible to use user function as a return value?

i hava so many questions.
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #7 on Fri 23 Sep 2011 11:16 PM (UTC)
Message
Look at my "getting started" videos:

http://www.gammon.com.au/forum/?id=10212

And others from that part of the forum.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Nick Gammon   Australia  (22,973 posts)  [Biography] bio   Forum Administrator
Date Reply #8 on Fri 23 Sep 2011 11:18 PM (UTC)
Message
Jedhi said:

like what do the trigger variables send_to="12" sequence="100" stand for? how can i use custom functions with triggers, how to interact with the mud(aard). for example how to get the rooms id and so on...



A lot of that is documented here:

http://www.gammon.com.au/forum/?id=7123

However in most cases you just use the GUI interface to create triggers and aliases, and it will put the correct things in there for you.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

Posted by Jedhi   (37 posts)  [Biography] bio
Date Reply #9 on Tue 27 Sep 2011 05:02 PM (UTC)
Message
thanx again.

i'm trying to create an alias for portals, in mushclient alias settings, which takes the portal out of bag, wears it and then enters.


dest = (%1)
portals = {}

portals['knossos'] = '288375488'

cmd = string.format('get %s bag', portals[dest])

Execute (cmd)


it doesn't work. seems i can't get the value of array. alias name is: prt *
syntax: prt knossos

where i went wrong with this?
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #10 on Tue 27 Sep 2011 05:28 PM (UTC)

Amended on Tue 27 Sep 2011 05:29 PM (UTC) by Twisol

Message
Use "%1" instead of (%1). The expansion syntax - %1 and @foo - isn't part of Lua, it's something MUSHclient does for you before the script is run. So when it sees %1, it just replaces it directly in the script with its value.

When Lua gets what you have now, it sees dest = (knossos), which doesn't mean what you want. It sees knossos as a variable name, and tries to find what value it has. Of course, there is no knossos variable, so dest just gets nil.

If you use "%1", Lua sees dest = "knossos". Lua knows "knossos" is a string, so dest gets that value.

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Jedhi   (37 posts)  [Biography] bio
Date Reply #11 on Wed 28 Sep 2011 09:26 AM (UTC)
Message

dest = %1
portals = {}

portals['knossos'] = '288375488'

portal = portals[dest]

cmd = string.format('get %s bag', portal)

Execute (cmd)


i still get the error. value for portal is nil
[Go to top] top

Posted by Jedhi   (37 posts)  [Biography] bio
Date Reply #12 on Wed 28 Sep 2011 12:07 PM (UTC)
Message
btw this (%1) is working in another alias!


lvl = (%1)
gear = {}
gear[41] = {284550683,284554076,284553104,284550901,284554217,284550117,284548701,231001032,58189977,284555249,253689542,284551389,284552750,284552936,284551681}
gear[61] = {284931904,284931530,284922537,284929035,284930297,284922748}
eqset = gear[lvl]

if eqset then
  j = table.getn(eqset)
  for i=1, j do
    s = string.format("get %s 272661297;wear %s", eqset,eqset)
    Execute (s)
  end
else
  print ("ERROR: Gear set not found")
end
[Go to top] top

Posted by Twisol   USA  (2,257 posts)  [Biography] bio
Date Reply #13 on Wed 28 Sep 2011 05:48 PM (UTC)
Message
You didn't add the quotes. You went from (%1) to %1 - you need "%1".

It works in the other one because, as far as I can tell, you expect %1 to contain a number. (42) is valid Lua code - it understands 42 to be a numeric literal value. But (foobar), which would be the case in your original code, is interpreted as a variable access, not a literal string value like "foobar".

'Soludra' on Achaea

Blog: http://jonathan.com/
GitHub: http://github.com/Twisol
[Go to top] top

Posted by Jedhi   (37 posts)  [Biography] bio
Date Reply #14 on Wed 28 Sep 2011 08:12 PM (UTC)
Message
got it. if anyone interested, this is how working version looks like:


portals = {}

portals["knossos"] = "288375488"
prt = portals["%1"]

cmd = string.format("get %s bag;wear %s;enter;dual dagger;put %s bag", prt, prt, prt)

Execute (cmd)
[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.


67,066 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 HostDash]