1. Post #1

    April 2011
    19 Posts
    Hello, I'm a beginner at Lua, so please don't be harsh.

    I'm wondering what's wrong with this;

    myTable={}
    myTable[1] = "TeoTown"
    myTable[2] = "is AWESOME!"
    myTable[3] = "is NOT awesome!"
    
    if Player:Nick() == "TeoTown" then
    	Msg (myTable[1] .. myTable [2])
    else 
    	Msg (myTable[1] .. myTable [3])
    end
    

    I keep getting this error messege in my console when I try to run it.

    [lua\helloworld.lua:7] attempt to index global 'Player' (a function value)

    Halp

  2. Post #2
    frosty802's Avatar
    April 2009
    445 Posts
    you haven't defined "Player" on line 6.

    try something like:

    local myTable={}
    myTable[1] = "TeoTown"
    myTable[2] = "is AWESOME!"
    myTable[3] = "is NOT awesome!"
    
    
    
    
    for k, v in pairs( player.GetAll() )     
        if v:Nick() == "TeoTown" then
            Msg (myTable[1] .. myTable [2])
        else
            Msg (myTable[1] .. myTable [3])
        end
    end
    
    Reply With Quote Edit / Delete Reply Windows 8 United Kingdom Show Events Agree Agree x 2Lua Helper Lua Helper x 2 (list)

  3. Post #3

    April 2011
    19 Posts
    I'll try to learn of that, thanks for the reply.

  4. Post #4
    Gold Member
    JeffDOA's Avatar
    July 2011
    120 Posts
    You could just replace player with ply and hook it.
    Would be better for those who are just starting, for looping can become complicated.


    myTable={}
    myTable[1] = "TeoTown"
    myTable[2] = "is AWESOME!"
    myTable[3] = "is NOT awesome!"
    
    
    function TeoIsAwesome(ply) 
        if ply:Nick() == "TeoTown" then
            Msg (myTable[1] .. myTable [2])
        else
            Msg (myTable[1] .. myTable [3])
        end
    end
    hook.Add("PlayerInitialSpawn", "IsTeoAwesome", TeoIsAwesome)
    
    Reply With Quote Edit / Delete Reply Windows 7 United States Show Events Agree Agree x 1 (list)

  5. Post #5
    Gold Member
    cis.joshb's Avatar
    January 2011
    1,875 Posts
    You could just replace player with ply and hook it.
    Would be better for those who are just starting, for looping can become complicated.


    myTable={}
    myTable[1] = "TeoTown"
    myTable[2] = "is AWESOME!"
    myTable[3] = "is NOT awesome!"
    
    
    function TeoIsAwesome(ply) 
        if ply:Nick() == "TeoTown" then
            Msg (myTable[1] .. myTable [2])
        else
            Msg (myTable[1] .. myTable [3])
        end
    end
    hook.Add("PlayerInitialSpawn", "IsTeoAwesome", TeoIsAwesome)
    
    You don't need to replace Player with ply. . .