Priority Curing System - Trying to Match Values in a Table

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Priority Curing System - Trying to Match Values in a Table

Post by Jules »

Hey everyone, it's me again...

So, after scouring the Forums, I couldn't quite find what I'm looking for. Here's my problem. I'm building a Priority Curing System for Lusternia, and the way I'm going to go about it is simple. When the affliction line pops up on the MUD screen, I have triggers set up to capture the line, add the appropriate affliction to a Lua table, then running an alias that searches the table for the appropriate affliction, and cures it. Here's how it should look:

Code: Select all

Trigger
Name: Prone
Matches: You sit down. 
Script:

listAdd( affs, "prone" )
send(cureAffs)
Now, how would I set up the alias to search for the appropriate value (in this case, "prone"), and fire off the correct cure for there? I already have alias' set up that will cure every affliction in the game (in the case of "prone", all I'd have to do is "stand"), so that's not a problem.

Also, related, how would I search for the appropriate value to find within the Table if I had more than one affliction in the list ("prone", "asleep", "bleeding", etc...)?

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Priority Curing System - Trying to Match Values in a Table

Post by Vadi »

So you basically want a key-value pair table, I'm guessing. Key would be the affliction name, value is if you have it or no. This page would be useful to you, in the "Tables as dictionaries" section. Along with this one: http://lua-users.org/wiki/TableLibraryTutorial

Though really, as someone who has built a successful system already, you'd get much more flexibility and simplicity if you use a series of if statements when doing the priority curing. You can still store the stuff in a table, but when curing, don't do a for loop on it.

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Re: Priority Curing System - Trying to Match Values in a Table

Post by Jules »

Thank you for the links! I'll look over them and see how that helps!

And could you go into your last statement a bit more? What do you mean by using a series of statements?

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Priority Curing System - Trying to Match Values in a Table

Post by Vadi »

Code: Select all

if affs.paralys == 1 then
    eat ("bloodroot")
else if affs.stupidity == 1 and not eating == 1 then
    eat ("goldenseal")
....
Like that. So not a for loop, but a series of if statements.

The flexibility comes from being able to use multiple conditions on one if.

User avatar
Jules
Posts: 118
Joined: Sun Oct 11, 2009 5:41 pm
Location: Plymouth State University - Sophomore

Re: Priority Curing System - Trying to Match Values in a Table

Post by Jules »

But will it still be fast?

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Priority Curing System - Trying to Match Values in a Table

Post by Vadi »

Yeah.

Verthar
Posts: 10
Joined: Tue Apr 27, 2010 3:12 pm

Re: Priority Curing System - Trying to Match Values in a Table

Post by Verthar »

if affs.paralys == 1 then
eat ("bloodroot")
else if affs.stupidity == 1 and not eating == 1 then
eat ("goldenseal")

Now with something like this, would it just be a further series of else if statements following, giving priority in that order? Or can they be bunched in some other way?

Sorry, I have a tough time understanding coding/scripting.

naftali
Posts: 138
Joined: Wed Jan 20, 2010 8:42 pm

Re: Priority Curing System - Trying to Match Values in a Table

Post by naftali »

you could. There are more elegant ways to do it though. For instance, if you wanted to you could do something like this:
Code: [show] | [select all] lua
priorities = { "paralysis", "stupidity", "weakness" }
cures = {
	paralysis = "bloodroot",
	stupidity = "goldenseal",
	weakness = "kelp"
}

for _,thisaff in ipairs(priorities) do
	if affs[thisaff] == 1 then
		eat(cures[thisaff])
		break
	end
end
There are lots of ways to improve this, but this is already much easier to deal with than a list of 50 if/then statements.

User avatar
tsuujin
Posts: 695
Joined: Fri Feb 26, 2010 12:59 am
Location: California
Contact:

Re: Priority Curing System - Trying to Match Values in a Table

Post by tsuujin »

I for one don't keep a list of variables, I keep a table that adds elements when I get them, and deletes them afterwards. This makes the parsing process faster, because it's easy to push through one or two elements, but much costlier to parse through... say.... 200 like in Lusternia.

User avatar
Vadi
Posts: 5042
Joined: Sat Mar 14, 2009 3:13 pm

Re: Priority Curing System - Trying to Match Values in a Table

Post by Vadi »

There are more than 200. More like 250+, and depends on how you set it up as well. I'm nearing 280ish and aren't done yet :|

Post Reply