Jump to content

table index is nil


Dice

Recommended Posts

function triggerSwarm( myName ) 
        runningStreaks[player] = getPlayerFromName ( myName ) 
        runningStreaks[player].x, runningStreaks[player].y, runningStreaks[player].z = getElementPosition ( runningStreaks[player] ) 
end 
  

I tested myName with outputChatBox and it passes from client to server successfully.

Link to comment
  • Moderators
    function triggerSwarm( player ) 
            if not runningStreaks[player] then 
            runningStreaks[player] = {} -- make it a table 
            end 
            runningStreaks[player]["name"] = getPlayerFromName (player )  
            -- insert name 
            runningStreaks[player].x, runningStreaks[player].y, runningStreaks[player].z = getElementPosition ( runningStreaks[player] )  
            -- insert pos 
    end 

Link to comment

also i dunno if im talking bs right now but do you ever do runningStreaks = {}

in other words construct the runningStreaks table

also y are u using both object notation and table notation ? is that allowed? idk legit question

  
runningStreaks[player]["name"] = getPlayerFromName (player ) 
 runningStreaks[player].x 
------> 
runningStreaks[player]["name"] = getPlayerFromName (player ) 
 runningStreaks[player]["x"] 
----- ? 
  

Link to comment
  • Moderators
also i dunno if im talking bs right now but do you ever do runningStreaks = {}

He must have because else it would start giving an error instead of a warning.

ERROR: attempt to index a nil value. (title: Re: table index is nil)

As far I know it is the same.

runningStreaks[player].x 
runningStreaks[player]["x"] 

But I prefer ["x"]. When I use table.x, I always get confused that x is a not defined value.

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...