• 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+ script function erro

jel

Member
Joined
Mar 22, 2014
Messages
302
Reaction score
12
I have a problem with this part of the system, any solution?

line 21: local creature = tile:getTopCreature()

part of the erro:
PHP:
local players = {}

            for x = dg[choiceId].FromPos.x, dg[choiceId].ToPos.x do

                for y = dg[choiceId].FromPos.y, dg[choiceId].ToPos.y do

                    for z = dg[choiceId].FromPos.z, dg[choiceId].ToPos.z do

                        local tile = Tile(x, y, z)

                        local creature = tile:getTopCreature()

                        if creature and creature:isPlayer() then

                            players[#players+1] = creature

                        end

                    end

                end

            end
[2022-31-05 16:45:04.500] [error] Lua script error: /home/global/data/scripts/custom/dungeos_creature.lua:callback
[2022-31-05 16:45:04.500] [error] /home/global/data/scripts/custom/dungeos_creature.lua:21: attempt to index local 'tile' (a nil value)
stack traceback:
[C]: in function '__index'
/home/global/data/scripts/custom/dungeos_creature.lua:21: in function </home/worldglobal/data/scripts/custom/dungeos_creature.lua:3>
 
Solution
You need to confirm that the tile exists before trying to get information from it.

Lua:
local tile = Tile(x, y, z)
if tile then
    local creature = tile:getTopCreature()
    if creature and creature:isPlayer() then
        players[#players+1] = creature
    end
end
You need to confirm that the tile exists before trying to get information from it.

Lua:
local tile = Tile(x, y, z)
if tile then
    local creature = tile:getTopCreature()
    if creature and creature:isPlayer() then
        players[#players+1] = creature
    end
end
 
Solution
You need to confirm that the tile exists before trying to get information from it.

Lua:
local tile = Tile(x, y, z)
if tile then
    local creature = tile:getTopCreature()
    if creature and creature:isPlayer() then
        players[#players+1] = creature
    end
end
thank you dear!
 
Back
Top