Ok I am tring to get an script to automaticly pick herbs based on a formula from 2 triggers and an alias.
alias would be like
pick (herb)
first trigger would catch on:
you have recovered balance -- and then do "plants"
second trigger will match on
(herb) (number) left.
so I was thinking it might work like
local herb
local pick
function start_pick (name, output, wildcs)
herb = wildcards[1]
Send("plants")
end
function check_pick (name, output, wildcs)
(something to check if the herb was the right one if not have another function to check it maybe?)
if wildcard[2] > 0 then
Send("pick ", herb)
else
Note("Cant pick anymore ", herb)
end
end
Well you are on the right track. Time to start testing your ideas. For some simple things you don't need a separate script file. I'll take your "pick" alias idea and show how it can all be done in the alias:
Now if you type "pick mushroom" (for example), it saves the word "mushroom" in the herbs variable, and sends "plants" to the MUD.
You can check the variable by typing into the command window:
/print (herb)
You should see echoed: mushroom
Now try the other things yourself. If you are posting, try using the copy function in the alias list to copy the actual alias as I have done, to avoid typing errors.
By the way, you need attention to detail in your scripts. For example:
function start_pick (name, output, wildcs)
herb = wildcards[1]
Send("plants")
end
The variable name you have used in the function line is "wildcs" but then you are using "wildcards" a line later. They have to be spelt the same.
function do_pick (name, output, wildcs)
if wildcs[2] == herb then
if wildcs[3] > "10" then
Send("pick ", herb)
else
Note("No more for you to pick.")
EnableTriggerGroup ("Herbs", false)
end
end
end
but now I notice its really spammy checking plants over and over again... so how could I gag it maybe?
But 20 is greater than 5. String compares work like that. It thinks the 5 is greater than the 2.
Now try:
/print (tonumber ("20") > 5) --> true
Why is it spamming? Is the other trigger not in the "Herbs" group?
It is really hard to help you, despite repeated requests you are only giving parts of what you are doing. You haven't posted your trigger that matches on "you have recovered balance".
all that does is do the command plants it was the only way I could figure to do it.
<triggers>
<trigger
custom_colour="2"
group="Herbs"
match="You have recovered balance on all limbs."
regexp="y"
sequence="99"
>
<send>plants</send>
</trigger>
</triggers>
which makes it spam cause its always checking to see the herbs. well I could have it just check once and store it as a variable, on how many I can pick and just subtract one when I do it... but sometimes when you pick the herb will grow more or someone till come in and pick them too, so I thought it best to do it this way.
the prompt will get spammier depending on the season because of the different herbs. and the trigger I didn't really know how to do so...
--You have recovered balance on all limbs.
plants
1410h, 1500m, 1860e, 10p ex-
The following plants are growing in this room:
A sprig of chervil (chervil) 11 left.
pick chervil
1410h, 1500m, 1860e, 10p ex-
You reach down and carefully harvest a sprig of chervil.
1410h, 1500m, 1860e, 10p e-
You have recovered balance on all limbs.
plants
1410h, 1500m, 1860e, 10p ex-
Across the heavens, the stars and moon challenge night's dark reign, revealing
familiar constellations that tell the tales of myth and legend.
1410h, 1500m, 1860e, 10p ex-
The following plants are growing in this room:
A sprig of chervil (chervil) 10 left.
No more for you to pick.--
to get all this in a course of several seconds trying to speak with others... is rather... hard...
[edit] the prompt was meant to go in this one... donno why I put it in the other...
Ok well I am wanting to make a table to go with this... but I'm not sure how I'd set up a script to look for the information I want, and I dont think I would need a linear scan for it either...
in my idioicy I didn't bother to look around and found out what was causing it not to work, simple error in my typing. So thank you for working with me on that, but I am still needing a way to make a none linear scan of a table i guess?
herbs = {
{ name = "Arnica" , month = "Klangiary"},
{ name = "Calamus" , month = "Dioni" },
{ name = "Chervil" , month = "Roarkian" },
{ name = "Colewort" , month = "Kiani" },
{ name = "Coltsfoot" , month = "Juliary" },
{ name = "Faeleaf" , month = "Juliary" },
{ name = "Flax" , month = "Estar" },
{ name = "Galingale" , month = "Shanthin" },
{ name = "Horehound" , month = "Vestia" },
{ name = "Juniper" , month = "Dioni" },
{ name = "Kafe" , month = "Urlachmar"},
{ name = "Kombu" , month = "Dioni" },
{ name = "Marjoram" , month = "Shanthin" },
{ name = "Merbloom" , month = "Estar" },
{ name = "Mistletoe" , month = "Avechary" },
{ name = "Myrtle" , month = "Estar" },
{ name = "Pennyroyal" , month = "Klangiary"},
{ name = "Reishi" , month = "Tzarin" },
{ name = "Rosehips" , month = "Shanthin" },
{ name = "Sage" , month = "Dioni" },
{ name = "Sargassum" , month = "Tzarin" },
{ name = "Sparkleberry" , month = "Dvarsh" },
{ name = "Weed" , month = "Estar" },
{ name = "Wormwood" , month = "Vestia" },
{ name = "Yarrow" , month = "Roarkian" },
}
function do_pick (name, output, wildcs)
-- a for here if thats even possible maybe...
-- check for name?
-- check for month?
-- check month vs curret month?
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
OK this is what I have so far.. I've put comments in where think things might go... but I'm not even sure where I could put something... and how to do it using what I have...
You are on the right track here. Maybe you can take a look at the other script for balances and understand what it is doing better. What to do next depends a fair bit on the MUD output and what you want to achieve.
If it is trying to eat herbs too often, then I would be keeping a table of the ones I need to eat (as I did in the other script) and then match the list of herbs I actually get to what I need. If none, then no more eating required.
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.
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...
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?
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:
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.
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:
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.
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?
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...
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 ""
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.
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)
hibernate_month = herbs [herb.month]
if (wildcs[2]) == herb then
if month == hibernate_month then
Note("Hibernating")
else
--TraceOut ("we have ", wildcs[4], " of ", wildcs[2])
if tonumber (wildcs[4]) > 10 then
Send("pick ", herb)
Note("There are ", ((wildcs[4])-10), " left to pick.")
else
Note("No more for you to pick.")
Send("inr all ", herb)
if spices == true then
Send("inr all spices")
spices = nil
end
DoAfterSpecial (2, 'EnableTriggerGroup ("Herbs", false)', 12)
end
end
end
end
thats my function, and I still dont see where it attempts to index it? I see wildcs[2] trying to check it, maybe I did something wrong there?
ok i changed herbs [herb.month] to herb ["month"] but I still get the same error. So i'm guessing that wouldn't be how to fix it maybe, mind helping me here, cause I have no clue how to fix it.
Just curious, but what IRE mud are you playing on? I've never heard of one that had seasons...well, I knew about perenials and the other ones, but people don't even care about that, they just harvest down to the minimum.
Lusternia's plants have certain months were they disappear, which is the ones in the table. the month after a room or two will come back with a few of the plant, then they must be reharvested. This script used to work with the older verions of mushclient, which I find very odd... and cant seem to tell... where I screwed up or how i might fix it.
I really don't think that using the latest version of MUSHclient will cause a Lua script to stop working. If you really think that is the case, download the earlier version of MUSHclient and see if that is really the problem.
Providing line-by-line debugging of users scripts is more than I can offer on this forum. I can help with suggestions about how to make things work with MUSHclient, and provide snippets which illustrate these ideas.
The suggestions I provide usually both compile and work in the test environment that I am using to demonstrate an idea. However it is up to you to make them work for a particular MUD.
If you are having problems with syntax errors in Lua, or working out how to get it to do things, then there is excellent documentation on the Lua site, an online "Lua Manual" which you can read, or download for local use. Or, you can buy it as a paperback book, as I have done.
You recent post about it "not working" is very non-specific. Does it not work because of compile-time errors, run-time errors, triggers not matching, script not doing what you expect, or what? It is very hard to debug a simple "it doesn't work" claim.
Its the same error I've had for awhile, i've said the error twice in this forum, you told me I was indexing a global variable, so I didn't know how to change it so it would work.
Error number: 0
Event: Run-time error
Description: [string "Alias: "]:4: attempt to index field `herb' (a nil value)
stack traceback:
[string "Alias: "]:4: in main chunk
Called by: Immediate execution
but i thought that herb = %1 would work, I've used it this way for a few things and it used to work, unless i'm mistake, how might i be able to fix that?