• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

TFS 1.X+ length of field (a nil value) error

undead mage

Active Member
Joined
Mar 25, 2012
Messages
364
Solutions
2
Reaction score
47
Location
Amsterdam
So I keep getting this error but I just can't figure out why I'm getting it.

Code:
attempt to get length of field 'playerPos' (a nil value) stack traceback:
[C]: in function '__len'


This is my config:
Code:
hohConfig = {
        [48901] = {                                 -- Movement ActionID
            requiredLevel = 175,                    -- Minimum level to enter the boss
            playerPos = {
                Position(165, 532, 11),
                Position(165, 533, 11),
                Position(165, 534, 11),
                Position(165, 535, 11),
                Position(165, 536, 11)
            },
            playerNewPos = Position(173, 513, 11), 
            bossPos = Position(175, 508, 11)        -- Where the boss will spawn
        }

This is my code:
Code:
        local storePlayers, playerTile = {}
        for i = 1, #hohConfig.playerPos do
            playerTile = Tile(hohConfig.playerPos[i]):getTopCreature()

            if playerTile:getLevel() < hohConfig.requiredLevel then
                player:sendTextMessage(MESSAGE_STATUS_SMALL, "All the players need to be level ".. hohConfig.requiredLevel .." or higher.")
                return true
            end

            storePlayers[#storePlayers + 1] = playerTile
        end
 
Solution
you're assuming hohConfig holds playerPos, but hohConfig holds a table held by key 48901 which then contains playerPos
you need to index hohConfig[48901].playerPos
you're assuming hohConfig holds playerPos, but hohConfig holds a table held by key 48901 which then contains playerPos
you need to index hohConfig[48901].playerPos
 
Solution
Back
Top