[Solved]Function works with one word search but not 2 words

Post Reply
Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

[Solved]Function works with one word search but not 2 words

Post by Knute »

Ok, I have a count function that get's triggered when I extract poison from certain critters.
What it does, is it searches the source for the poison, then updates the count in my count table, and then sets the display in my display table so that another function that it calls will update the display.

So, for something like a rattlesnake, it does what it's supposed. It finds the right poison, and then updates accordingly. However, when it comes to something like a sea anemone, it does nothing. I've been trying to figure out what I'm missing.
Code: [show] | [select all] lua
function extractPoisonCount(source)
		local poisontype = psnTblSrcType(source)
		cntTbl[poisontype] = cntTbl[poisontype] + 1
		dsplyOptionOn(poisontype)
end
The trigger is:
Code: [show] | [select all] lua
You massage the venom glands of the corpse of a (.*), and carefully extract the poison into (.*) vial.
The script that is called is:
Code: [show] | [select all] lua
extractPoisonCount(matches[2])
The script that actually does the search (which works outside of the above function, btw):
Code: [show] | [select all] lua
function psnTblSrcType(arg)
		for k,v in pairs(psntbl) do
				search = table.contains(v, arg)
				if search == true then
						return v.poison
				end
		end
end
Any ideas?
Last edited by Knute on Mon May 31, 2010 2:17 am, edited 1 time in total.

Ryan
Posts: 10
Joined: Mon Jun 22, 2009 1:15 am

Re: Function works with one word search but not 2 words

Post by Ryan »

I don't see any problems in the code you posted. But there are a few places where I know I'd be likely to get errors:
- cntTbl[poisonType] isn't initialized to 0 for sea anemone poison types correctly (which means the multi-word thing would just be a coincidence)
- psntbl isn't initialized properly with multi-word critters, so psnTblSrcType("sea anemone") doesn't find anything and just returns nil
- something weird in dsplyOptionOn, although then I can't explain the multi-word thing.

So basically, there could be a bug on any line. Not very helpful, I guess. Open up the debug window and extract from a sea anemone to see if you can find exactly where things go off the rails.

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: Function works with one word search but not 2 words

Post by Knute »

I'll try that. I have my other tables being initialized off of my psntbl, and other's that I have created.

Here's the one that initializes the cntTbl.

It just runs through the tables, and puts the values into another table with their count.
So then when the variable cntTbl.rattlesnake is used, it will display the count.
Code: [show] | [select all] lua
>cntTbl = {}

function cntTblInit()
        for _, v in pairs(notificationWindowItemsTable) do
                cntTbl[v] = 0
        end
        for _, v in pairs(notificationWindowFollowTable) do
                cntTbl[v] = 0
        end
        for _, v in pairs(psntbl) do
                cntTbl[v.poison] = 0
        end
end

cntTblInit()
Actually, the "sea anemone" poisontype, isn't the issue. The table is set up for the poison that the sea anemone produces. I have a function "psnTblSrcType()" that checks for the sea anemone and then returns the poison, so then the appropriate table/s can be updated.

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: Function works with one word search but not 2 words

Post by Knute »

The only thing that I can think of that would be a problem would be that maybe I should use a character by character search (as in Vadi's enemy highlighter) rather than the table.contains function. Not sure though.

Knute
Posts: 87
Joined: Fri Mar 05, 2010 12:08 am

Re: [Solved]Function works with one word search but not 2 words

Post by Knute »

Ok, I figured out what was going on, and I feel like an idiot because of it.

There was nothing wrong with my code. I had an alias that when I put in "sea anemone" (minus the quotes) it would return saxitin.

It turns out that my trigger was the problem.

The message is something to the effrect of:
"You massage the venom glands of the corpse of a sea anemone, and carefully extract the poison into a pearl vial."

My trigger that I was using was:
Code: [show] | [select all] lua
"You massage the venom glands of the corpse of a (.*), and carefully extract the poison into (.*) vial."
This trigger worked fine for something like a rattlesnake, but a sea anemone or a large python, would not work. Apparently, in this situation the first (.*) only caught the first word, and the second one contained the rest.

When I simply removed the "into (.*) vial." everything works as it should.

Even though I feel like an idiot about it, it brings up a good point though, is this the expected behavior of having 2 such open wildcards in a trigger? I don't NEED to have a listing of which type of vial it is in, but I'm just curious.

Post Reply