Register forum user name Search FAQ

Gammon Forum

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 ➜ Lua ➜ Simple script

Simple script

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


Pages: 1  2 3  

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #15 on Sat 10 Dec 2005 09:24 PM (UTC)
Message
Its not for eatting *scratch* what I am trying to do is make a script that picks herbs from the room down to 10 automaticly right... but because some herbs hibernate during a certain month, you shouldn't really pick them cause you might have a chance to ruin the next growing period for it... so I am trying to check it.

Everything turns around in the end
Top

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #16 on Sat 10 Dec 2005 09:41 PM (UTC)

Amended on Sun 11 Dec 2005 11:44 PM (UTC) by Nick Gammon

Message

function do_pick (name, output, wildcs)
 for _, v in ipairs (herbs) do
  if month == v.month then
   Note("Hibernating")
  else
   if wildcs[2] == herb then
    if tonumber (wildcs[4]) > 10 then
     Send("pick ", herb)
    else
     Note("No more for you to pick.")
     Send("inr all ", herb)
     DoAfter(4, EnableTriggerGroup ("Herbs", false))
    end
   end
 end
end
end


i've tried doing it this way, and it works kinda... I donno if it actually checks to see what month it is... but then it spams the game with pick (herb) many many times... so.... I'm guessing I did something really wrong here...

Everything turns around in the end
Top

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #17 on Sun 11 Dec 2005 10:34 PM (UTC)

Amended on Sun 11 Dec 2005 10:35 PM (UTC) by Metsuro

Message
The problem I am guessing that its not looking for the herb i want but its checking all herbs vs the month right? so how might I change it to look for just the one herbs month? also at the end of the 4 seconds I believe it saids 5 to the game... and I dont know why?

Everything turns around in the end
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #18 on Mon 12 Dec 2005 12:18 AM (UTC)
Message
OK, let's look at your function. You have to think logically if you are going to make it work ...


function do_pick (name, output, wildcs)
 table.foreach (wildcs, print)

 for _, v in ipairs (herbs) do
  if month == v.month then
   Note("Hibernating")
  else
   if wildcs[2] == herb then
    if tonumber (wildcs[4]) > 10 then
     Send("pick ", herb)
    else
     Note("No more for you to pick.")
     Send("inr all ", herb)
     DoAfter(4, EnableTriggerGroup ("Herbs", false))
    end
   end
 end



I've added the line in bold to print the wildcards you are getting. Based on the earlier trigger you had (and that is the only one I have to work with), if you match on:


A sprig of chervil (chervil) 11 left.


... the wildcards are:


1 A sprig of chervil
2 chervil
3 11
0 A sprig of chervil (chervil) 11 left.


So straight away we see your tests for wildcs[4] are not going to be a big success, as there is no wildcard 4.

Next thing is, we see from your table:


{ name = "Chervil" , month = "Roarkian" },


Now you have "Chervil" in the table, but the wildcard is "chervil". I know it is similar, but they are different words.

Then you have a test:


if month == v.month then


Where is "month" defined? What is in it?

Moving on, I see:


if wildcs[2] == herb then


How is "herb" set up? Do you mean:


if wildcs[2] == v.name then


That would compare the herb in the table to the one you got. I can't see the point in going through the table if you don't compare the herb names.

Quote:

also at the end of the 4 seconds I believe it saids 5 to the game ...


You have this:


DoAfter(4, EnableTriggerGroup ("Herbs", false))


What that will do, is after 4 seconds send the "return code" from EnableTriggerGroup. The definition for EnableTriggerGroup says it returns "A count of the number of items in that group". Thus I presume there are 5 things in the group, and it is sending 5 to the MUD.

What you want is something slightly different. You want to execute 'EnableTriggerGroup ("Herbs", false)' as a command after 4 seconds, not right now. So it should read:


DoAfterSpecial (4, 'EnableTriggerGroup ("Herbs", false)', 12)


What that does, is after 4 seconds send the string 'EnableTriggerGroup ("Herbs", false)' to the scripting engine (destination 12) to be executed then.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #19 on Mon 12 Dec 2005 12:36 AM (UTC)
Message
<aliases>
<alias
match="pick *"
enabled="y"
send_to="12"
sequence="100"
>
<send>herb = "%1"
EnableTriggerGroup ("Herbs", true)
Send "plants"</send>
</alias>
</aliases>

<triggers>
<trigger
group="Herbs"
keep_evaluating="y"
match="^(.*) \((.*?)\) (.*) (.*?) left\.$"
omit_from_output="y"
regexp="y"
script="do_pick"
sequence="100"
>
</trigger>
</triggers>

I had to change the trigger because of the space difference in each one. from the (chervil) to the number in the room.

Herb is the variable I use to see which herb I am currently picking. Now what I want to do is get the herb i am currently pick see what month its hibernation is, and if it so happens to be that the month is its hibernation month it wont pick it. However, I am not sure how I need to set it up to check for the one specific herb.

Everything turns around in the end
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #20 on Mon 12 Dec 2005 01:19 AM (UTC)
Message
Quote:

I want to do is get the herb i am currently pick see what month its hibernation is ...


The easiest way of doing that is to rejig your table a bit. You had a table of tables, but to look up the month corresponding to a herb, this is simpler:

 
herbs = {
        arnica    = 'Klangiary',
        calamus   = 'Dioni',
        chervil   = 'Roarkian',
        colewort  = 'Kiani',
        coltsfoot = 'Juliary',
        faeleaf   = 'Juliary',
        flax      = 'Estar',
        galingale = 'Shanthin',
        horehound = 'Vestia',
        juniper   = 'Dioni',
        kafe      = 'Urlachmar',
        kombu     = 'Dioni',
        marjoram  = 'Shanthin',
        merbloom  = 'Estar',
        mistletoe = 'Avechary',
        myrtle    = 'Estar',
        pennyroyal = 'Klangiary',
        reishi    = 'Tzarin',
        rosehips  = 'Shanthin',
        sage      = 'Dioni',
        sargassum = 'Tzarin',
        sparkleberry = 'Dvarsh',
        weed      = 'Estar',
        wormwood  = 'Vestia',
        yarrow    = 'Roarkian',
}

print (herbs.yarrow) -- Roarkian



See how in this case I simply put the herb name in, and get its month? In your case you might say:


foundherb = wildcs [2]
hibernate_month herbs [foundherb]

if month == hibernate_month then
   Note("Hibernating")
else
-- blah blah





What might help you is the TraceOut function which is new to MUSHclient from version 3.68 onwards. This lets you put debugging stuff into your script, which only appears if you turn on Game -> Trace.

I have modified your existing script (I know it isn't working, but to show you the idea) to add some traces:


function do_pick (name, output, wildcs)
 TraceOut "in do_pick"

 table.foreach (wildcs, 
    function (k, v) TraceOut ("wildcard ", k, " = ", v) end  )

 TraceOut ("month = ", month)
 TraceOut ("herb = ", herb)

 for _, v in ipairs (herbs) do
  if month == v.month then
   Note("Hibernating")
  else
   if wildcs[2] == herb then 
    TraceOut ("we have ", wildcs[4], " of ", wildcs[2])
    if tonumber (wildcs[4]) > 10 then
     Send("pick ", herb)
    else
     Note("No more for you to pick.")
     Send("inr all ", herb)
     DoAfter(4, EnableTriggerGroup ("Herbs", false))
    end
   end
 end
end
end


Now if we go to the Game menu and turn Trace on, and then find a herb, we see this:


TRACE: Matched trigger "^(.*) \((.*?)\) (.*?) left\.$"
TRACE: Executing trigger script "do_pick"
TRACE: in do_pick
TRACE: wildcard 1 = A sprig of chervil
TRACE: wildcard 2 = chervil
TRACE: wildcard 3 = 11
TRACE: wildcard 0 = A sprig of chervil (chervil) 11 left.
TRACE: month = nil
TRACE: herb = nil


However as soon as we turn Trace off, the spammy output goes away. So it is useful to have your debugging code there, until everything is working.

Here I am displaying the wildcard contents, and the values of 'month' and 'herb' so I can see what is going on.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #21 on Mon 12 Dec 2005 11:57 PM (UTC)
Message
After a little toying around I got this...

TRACE: Matched alias "pick *"
plants
TRACE: Executing trigger script "do_pick"
TRACE: in do_pick
TRACE: wildcard 1 = A sprig of marjoram
TRACE: wildcard 2 = marjoram
TRACE: wildcard 3 =
TRACE: wildcard 4 = 60
TRACE: wildcard 0 = A sprig of marjoram (marjoram) 60 left.
TRACE: month = Roarkian
TRACE: herb = chervil
TRACE: Executing trigger script "do_pick"
TRACE: in do_pick
TRACE: wildcard 1 = A stem of galingale
TRACE: wildcard 2 = galingale
TRACE: wildcard 3 =
TRACE: wildcard 4 = 60
TRACE: wildcard 0 = A stem of galingale (galingale) 60 left.
TRACE: month = Roarkian
TRACE: herb = chervil
TRACE: Executing trigger script "do_pick"
TRACE: in do_pick
TRACE: wildcard 1 = A sprig of chervil
TRACE: wildcard 2 = chervil
TRACE: wildcard 3 =
TRACE: wildcard 4 = 45
TRACE: wildcard 0 = A sprig of chervil (chervil) 45 left.
TRACE: month = Roarkian
TRACE: herb = chervil
Hibernating

I think I can say... it works now woo.

Everything turns around in the end
Top

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #22 on Tue 13 Dec 2005 01:51 AM (UTC)
Message
argh ok now i have another problem, when there is none of a herb in the room i am wanting to pick, the triggers stay on, i need a way to turn them off if there is none of that herb in the room, any suggestions on how i could do that?

Everything turns around in the end
Top

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #23 on Tue 24 Jan 2006 02:08 AM (UTC)
Message
Heh, alrighty back to my harvesting script! hehe. I've had it working the way I wanted since my last post, but now I need a table with each herbs price, and i thought i could make a table with many tables in it, but I dont know if i can do it and still work the way it does now...

Everything turns around in the end
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #24 on Tue 24 Jan 2006 05:25 AM (UTC)
Message
You can certainly make a table with tables in it, but it won't work exactly the same as now.


herbs = {
        arnica    = { month = 'Klangiary', price = 20 },
        calamus   = { month = 'Dioni', price = 20 },
-- and so on ... 
}


Now you need to reference the key in the subtable to get the items (month, price), like this:


print (herbs.arnica.month, herbs.arnica.price) --> Klangiary 20


- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #25 on Thu 26 Jan 2006 07:48 PM (UTC)
Message
after going to 2.73 i get this error now.

Error number: 0
Event: Run-time error
Description: [string "Plugin"]:261: attempt to index global `herb' (a string value)
stack traceback:
[string "Plugin"]:261: in function `do_pick'
Called by: Function/Sub: do_pick called by trigger
Reason: processing trigger ""

not sure whats happening.

Everything turns around in the end
Top

Posted by Ked   Russia  (524 posts)  Bio
Date Reply #26 on Fri 27 Jan 2006 02:12 AM (UTC)
Message
You probably accidentally set the herb object to a string. Try doing a search for "herb =" in your plugin file, and see if there's a string being assigned to it somewhere.
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #27 on Fri 27 Jan 2006 02:26 AM (UTC)
Message
Are you getting confused between "herb" and "herbs"? One is the name of a herb, the other is a table of herbs.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Metsuro   USA  (389 posts)  Bio
Date Reply #28 on Fri 27 Jan 2006 08:02 PM (UTC)
Message
i have an alias that sets herb to a string because its a word, and i thought a word had to be a string?

Everything turns around in the end
Top

Posted by Nick Gammon   Australia  (23,133 posts)  Bio   Forum Administrator
Date Reply #29 on Fri 27 Jan 2006 11:29 PM (UTC)
Message
You get your exact error message if you try to do this:


herb = "arnica"
print (herb [22]) --> attempt to index global `herb' (a string value)


You cannot index into a string. Do you mean "herbs" which is your table of herbs?

- Nick Gammon

www.gammon.com.au, www.mushclient.com
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.


97,799 views.

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

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

Go to topic:           Search the forum


[Go to top] top

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