Using Info from a Table in an alias

Post Reply
Guilend
Posts: 36
Joined: Fri Mar 09, 2018 1:21 am

Using Info from a Table in an alias

Post by Guilend » Sat Aug 18, 2018 9:23 pm

I had help with this about a month ago, but I ended up going another rout, but now I do need it and now I can't remember how to do it.
this is an example of the table since i have no idea how to describe it in words.
[]puppets
[1]pup
[]id
[2]pup
[]id

There is other info other then "[]id" but it's the "[]id" that i am wanting to use in this instance.
I want to make an alias to use them but i can't remember how I was told to do it.
It was something like "puppets.id" and i think it had a tonumber in there somewhere.

Jor'Mox
Posts: 1099
Joined: Wed Apr 03, 2013 2:19 am

Re: Using Info from a Table in an alias

Post by Jor'Mox » Sun Aug 19, 2018 12:05 am

So, it depends on how you created the table. Table values are either indexed or keyed, and which one you used is going to influence how you can access that data. If, in creating the individual entries in your larger puppet table, you did something like this: table.insert(puppets,{id = ###}), then you could use puppets[1].id to get the id for the first entry in the table, puppets[2].id to get the second, etc. You could also get the same data like this: puppets[1]["id"], which is useful if the key you used contains a character that isn't a letter, a number, or an underscore. If instead you did it like this: table.insert(puppets,{###}), then you would need to know the position of the ID within the table, and use that index. If it were the first entry, you would do that like this: puppets[1][1] to get the first id, and puppets[2][1] to get the second.

Guilend
Posts: 36
Joined: Fri Mar 09, 2018 1:21 am

Re: Using Info from a Table in an alias

Post by Guilend » Sun Aug 19, 2018 1:38 am

I used a trigger chain to create it.

First trigger is
pup = {}

second trigger is
local pup = tonumber(matches[2])
local id = matches[3]
local lvl = tonumber(matches[4])
local hp = tonumber(string.format("%.1f", (100 / tonumber(matches[6])) * tonumber(matches[5])))
local room = matches[7]
puppets[pup] = {
id = id,
lvl = lvl,
hp = hp,
room = room,
hardened = line:find('hardened', 1, true) and true or false,
magical = line:find('magical', 1, true) and true or false
}
Third of course it just the closing chain trigger

Guilend
Posts: 36
Joined: Fri Mar 09, 2018 1:21 am

Re: Using Info from a Table in an alias

Post by Guilend » Sun Aug 19, 2018 5:39 am

oh wow, thanks, it did work. I appreciate it.

puppets[tonumber(1)].id

that did the trick

User avatar
demonnic
Posts: 570
Joined: Sat Dec 05, 2009 3:19 pm

Re: Using Info from a Table in an alias

Post by demonnic » Sun Aug 19, 2018 7:54 am

you shouldn't need to tonumber(1), you can just use 1. You have to use tonumber on matches from aliases and perl regex triggers because they're read in as strings, and have to be changed before math can be done with them. should be able to just use puppets[1].id

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests