Tables in LUA

nepluto
Unregistered
 
Post: #1
HI, Im quite new to this place, but i have been working on teaching myself LUA scripting for MOD creation for the game World of Warcraft. I have been struggling on one thing though, which are tables. I understand how to create and edit them, my problem is, i was wondering if there was a way to use more then 1 value in em, such as a players Name, Rank, and online status or even just Name and Rank.

As the mod i am creating needs to have sort of a "Leader" if you will to display Text back into Guild chat. But i want to find the leader by the highest ranking person, then alphabetical order, incase there are more then one person of that rank. If this is not possible or you need any other information about it please let me know. any help would be greatly appreciated! thank you for your time.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #2
I don't really understand how you can know how to use a table with one value but not more.... anyway

Code:
-- creating a table with more than one value:
table = {
    name = "Hello",
    rank = 13
}

-- accessing values from the table
x = table.name
y = table.rank
-- or
x = table["name"]
y = table["rank"]

-- changing the values
table.name = "Hi"
table.rank = 14
-- or
table["name"] = "Hi"
table["rank"] = 14
Quote this message in a reply
Member
Posts: 715
Joined: 2003.04
Post: #3
I just picked up Beginning Lua Programming
A great reference. It may be more than you need at the moment,
but it covers in detail what you will get into as you go along.
The amount of information on tables is too extensive for me to even list.
Quote this message in a reply
nepluto
Unregistered
 
Post: #4
No. Maybe i said it wrong, I can use a table with more then on value. My problem is actually sorting that table. yes the whole table.sort and crap. let me show you my example, maybe this will help.


My table has 2 values. Name,RankIndex. I need to sort it by RankIndex which is a value from 1-5. of course 5 being the highest. I then am looking to sort all the values of 5 in alphabetical order. and then so on.

If you still don't understand what im talking about feel free to let me know. But i did not ever say i did not know how to USE a table with more then one value.
Quote this message in a reply
Luminary
Posts: 5,143
Joined: 2002.04
Post: #5
Er, that's precisely what you first paragraph in your first post does say. You never even mentioned sorting in your first post Rasp

This question makes much more sense Wink

I think the documentation, eg. here: http://lua-users.org/wiki/TableLibraryTutorial should be perfectly understandable, but in your case, your comparison function is going to look something like:

Code:
function(player0, player1)
    if player0.rank < player1.rank then
        return true
    elseif player1.rank < player0.rank then
        return false
    end

    if player0.name < player1.name then
        return true
    elseif player1.name < player0.name then
        return false
    end

    return false
end
Quote this message in a reply
nepluto
Unregistered
 
Post: #6
nepluto Wrote:As the mod i am creating needs to have sort of a "Leader" if you will to display Text back into Guild chat. But i want to find the leader by the highest ranking person, then alphabetical order, incase there are more then one person of that rank. If this is not possible or you need any other information about it please let me know. any help would be greatly appreciated! thank you for your time.

ok so i didn't exactly state SORT them. But anyway. thanks for the help. i appreciate it.
Quote this message in a reply
Post Reply