checking variable against a list

Post Reply
DanaLea73
Posts: 46
Joined: Fri Jul 09, 2010 12:04 am

checking variable against a list

Post by DanaLea73 » Tue Sep 14, 2010 11:53 pm

I'm not quite sure how to ask this, but here goes...

When I level (on aardwolf) if I gained any new skills or spells with that level, part of the level up text includes lines that tell me what those new spells or skills are. I've written a simple little script that send that info to a chat window so it doesn't get lost in the scrolling battle spam.

However, I'd like to get clever with it. I'd like to take the info and compare it to a list, and if its on that list, then send it to the chat window, if it doesn't then not to (spells and skills I don't bother ever using will not get sent). I could do a series of elseif but we are talking dozens and dozens of penitential matches. I'm thinking an array would be better? I think I know how to create an array
Code: [show] | [select all] lua
arrayname = {item1, item2, item3, etc}
but no real idea how to check a matches[2] again that. Can someone help?

-dana

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

Re: checking variable against a list

Post by Vadi » Wed Sep 15, 2010 12:19 am

You can use table.contains(mytable, thing) to try that. Ie, if table.contains(arrayname, matches[2]) then echo("we have it!") end

DanaLea73
Posts: 46
Joined: Fri Jul 09, 2010 12:04 am

Re: checking variable against a list

Post by DanaLea73 » Wed Sep 15, 2010 5:18 am

can arrays/tables have elements with spaces? can
  • Harden body
be one element of an array?

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

Re: checking variable against a list

Post by tsuujin » Wed Sep 15, 2010 5:24 am

DanaLea73 wrote:can arrays/tables have elements with spaces? can
  • Harden body
be one element of an array?
Code: [show] | [select all] lua
var = {}
var["test key"] = "this is the value"
var[50] = "another value"
var["third"] = 3
These are all completely valid. Lua is not strict in the least with data typing in their lists.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest