Jump to content

inexperienced with tables, Please help


Recommended Posts

So here's what I have:

A table(client & server)

  
class = { 
    { 
        police={ 
            guard = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, PER=1}, 
            supervisor = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, PER=1} 
        }, 
        Prisoner={ 
            fresh = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, SLT=1}, 
            hardened = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, SLT=1} 
        } 
    } 
} 
  

A clientside for loop in a seperate file

(for testing purposes i only output strings)

  
        for pIndex, classes in ipairs(class) do --Loop the classes 
            outputDebugString(tostring(pIndex).." "..tostring(classes)) 
            for index, classPackage in ipairs(classes['police']) do 
                outputChatBox(tostring(index).." "..tostring(classPackage)) 
            end      
        end 
  

And this error in merely EVERY attempt

dBNYgUj.png

As you can see I'm trying to retreive a table value in the 2nd for loop, But even if I remove the ['police'] part out of the table, I get no error, but also no string. Why isn't this working? I've been editing this for nearly 2 hours!

Link to comment

the table is not called "classes", is "class"

  
  
        for pIndex, classes in ipairs(class) do --Loop the classes 
            outputDebugString(tostring(pIndex).." "..tostring(classes)) 
            for index, classPackage in ipairs(classes) do 
                outputChatBox(tostring(index).." "..tostring(classPackage)) 
            end     
        end 
  
  

Link to comment
        for pIndex, class in ipairs(class) do --Loop the classes 
            outputDebugString(tostring(pIndex).." "..tostring(class)) 
            for index, classPackage in ipairs(class['police']) do 
                outputChatBox(tostring(index).." "..tostring(classPackage)) 
            end     
        end 
  
        for pIndex, class in ipairs(class) do --Loop the classes 
            outputDebugString(tostring(pIndex).." "..tostring(class)) 
            for index, classPackage in ipairs(class['Prisoners']) do 
                outputChatBox(tostring(index).." "..tostring(classPackage)) 
            end     
        end 

Link to comment
        for pIndex, class in ipairs(class) do --Loop the classes 
            outputDebugString(tostring(pIndex).." "..tostring(class)) 
            for index, classPackage in ipairs(class['police']) do 
                outputChatBox(tostring(index).." "..tostring(classPackage)) 
            end     
        end 
  
        for pIndex, class in ipairs(class) do --Loop the classes 
            outputDebugString(tostring(pIndex).." "..tostring(class)) 
            for index, classPackage in ipairs(class['Prisoners']) do 
                outputChatBox(tostring(index).." "..tostring(classPackage)) 
            end     
        end 

yh30.png

Link to comment

WIth your first script, I got no errors.

class = { 
    { 
        police={ 
            guard = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, PER=1}, 
            supervisor = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, PER=1} 
        }, 
        Prisoner={ 
            fresh = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, SLT=1}, 
            hardened = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, SLT=1} 
        } 
    } 
} 
  
  
        for pIndex, classes in ipairs(class) do --Loop the classes 
            outputDebugString(tostring(pIndex).." "..tostring(classes)) 
            for index, classPackage in pairs(classes['police']) do 
                outputChatBox(tostring(index).." "..tostring(classPackage)) 
            end     
        end 

Link to comment
WIth your first script, I got no errors.
class = { 
    { 
        police={ 
            guard = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, PER=1}, 
            supervisor = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, PER=1} 
        }, 
        Prisoner={ 
            fresh = {STR=3, DEF=3, INT=3, STA=3, HAN=3, INV=3, WEP=3, RES=3, SLT=1}, 
            hardened = {STR=5, DEF=5, INT=5, STA=5, HAN=5, INV=5, WEP=5, RES=5, SLT=1} 
        } 
    } 
} 
  
  
        for pIndex, classes in ipairs(class) do --Loop the classes 
            outputDebugString(tostring(pIndex).." "..tostring(classes)) 
            for index, classPackage in pairs(classes['police']) do 
                outputChatBox(tostring(index).." "..tostring(classPackage)) 
            end     
        end 

I've checked it, and now I get good results....I still don't get it.

Link to comment

Since I recently made this topic, Let bring up the same issue, as I have no idea why this isn't working.

the table is the same, now my code

  
    local str, def, int, sta, han, inv, wep, res, slt, per = nil 
    wdwCreateCharacter=guiCreateWindow(sx*0.4, sy*0.4, sx*0.2, sy*0.2, "Pick a name", false) 
    for pIndex, classes in ipairs(class) do --Loop the classes 
        outputChatBox(tostring(classes)) 
        for index, classPackage in pairs(classes['police']) do 
            if (source==btnGuard) then 
                for i, skills in pairs(classPackage['guard']) do 
                    str, def, int, sta, han, inv, wep, res, per = unpack(skills) 
                end 
            elseif (source==btnSergeant) then 
                for i, skills in pairs(classPackage['sergeant']) do 
                    str, def, int, sta, han, inv, wep, res, per = unpack(skills) 
                end 
            end 
        end 
    end 
  
    for pIndex, classes in ipairs(class) do --Loop the classes   
        for index, classPackage in pairs(classes['prisoner']) do 
            if (source==btnFresh) then 
                str, def, int, sta, han, inv, wep, res, per = unpack(classPackage['fresh']) 
            elseif (source==btnHardened) then 
                str, def, int, sta, han, inv, wep, res, per = unpack(classPackage['hardened']) 
            end 
        end 
    end 
  

The debugscript

0Izdxn6.png

This is the line we're talking about in the debug.

  
 for i, skills in pairs(classPackage['guard']) do 
  

Now I tried solving it with pairs & ipairs (before I spent another 2 hours on the same issue), but that's not the issue. What do I miss here?

Note, It starts in the guard area, I havent edited the bottom prisoners for chunk

Link to comment
    local str, def, int, sta, han, inv, wep, res, slt, per = nil 
    wdwCreateCharacter=guiCreateWindow(sx*0.4, sy*0.4, sx*0.2, sy*0.2, "Pick a name", false) 
    for pIndex, classes in ipairs(class) do --Loop the classes 
        outputChatBox(tostring(classes)) 
        if (source==btnGuard) then 
            local skills = classes["police"]['guard'] 
            outputChatBox ( skills.STR ) 
        elseif (source==btnSergeant) then 
            local skills = classes["police"]['sergeant'] 
            outputChatBox ( skills.STR ) 
        end 
    end 

Link to comment
    local str, def, int, sta, han, inv, wep, res, slt, per = nil 
    wdwCreateCharacter=guiCreateWindow(sx*0.4, sy*0.4, sx*0.2, sy*0.2, "Pick a name", false) 
    for pIndex, classes in ipairs(class) do --Loop the classes 
        outputChatBox(tostring(classes)) 
        if (source==btnGuard) then 
            local skills = classes["police"]['guard'] 
            outputChatBox ( skills.STR ) 
        elseif (source==btnSergeant) then 
            local skills = classes["police"]['sergeant'] 
            outputChatBox ( skills.STR ) 
        end 
    end 

Great, thank you!

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...