• 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!

RevScripts bad argument #1 to 'pairs' (table expected, got nil)

Svira

Active Member
Joined
Jan 27, 2008
Messages
263
Solutions
11
Reaction score
35
Hello, I've been struggling with a table problem for a few days now. Any idea how to solve it? below error code:
Code:
[2023-16-01 14:48:13.903] [error] Lua script error:
scriptInterface: [Main Interface]
scriptId: [(Unknown scriptfile)]
timerEvent: [in a timer event called from:]
 callbackId:[]
function: []
error [...ta-otservbr-global-tapierwsza/scripts/custom/effectt.lua:105: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
        [C]: at 0x55f798099da0
        [C]: in function 'pairs'
        ...ta-otservbr-global-tapierwsza/scripts/custom/effectt.lua:105: in function <...ta-otservbr-global-tapierwsza/scripts/custom/effectt.lua:96>]

Here we have part of the code:
Lua:
function Position:sendDistanceAnimateEffect(toPosition, distanceEffect, queueEffect)
    local distance = self:getDistance(toPosition)
    local direction = self:getDirection(toPosition)
    local pos = Position(self.x, self.y, self.z)
    for i = 1, distance do
        local nextPos = Position(pos.x, pos.y, pos.z)
        nextPos:getNextPosition(direction)
        addEvent(function (pos, nextPos)
            pos:sendMagicEffect(queueEffect)
            pos:sendDistanceEffect(nextPos, distanceEffect)
            local rangeX = 5
            local rangeY = 5           
            local specs = Game.getSpectators(Position(1115, 167, 6), false, false, rangeX, rangeY)
            for _, spec in pairs(specs) do
            local creatures = Tile(nextPos):getCreatures(specs)
            -- if creature == nil then return false end
            for k, creature in pairs(creatures) do
                if creature:isPlayer() then
                print(" ..creature.. ")
                    creature:teleportTo(mietek.teleportWhenHitPlayer)
                end
            end
        end end, 125 * i, pos, nextPos)
        pos = nextPos
    end
end
 
Solution
have this:

Lua:
scriptInterface: [Main Interface]
scriptId: [(Unknown scriptfile)]
timerEvent: [in a timer event called from:]
 callbackId:[]
function: []
error [/home/ots/data-otservbr-global/scripts/custom/effectt.lua:106: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
        [C]: at 0x55a46eb07da0
        [C]: in function 'pairs'
        /home/ots/data-otservbr-global/scripts/custom/effectt.lua:106: in function </home/ots/data-otservbr-global/scripts/custom/effectt.lua:96>]

Lua:
function Position:sendDistanceAnimateEffect(toPosition, distanceEffect, queueEffect)
  local pos       = Position(self) -- copy
  local distance  = self:getDistance(toPosition)
  local direction =...
change
Lua:
 for _, spec in pairs(specs) do
            local creatures = Tile(nextPos):getCreatures(specs)
            -- if creature == nil then return false end
            for k, creature in pairs(creatures) do
                if creature:isPlayer() then
                print(" ..creature.. ")
                    creature:teleportTo(mietek.teleportWhenHitPlayer)
                end
            end

to

Code:
if(specs) then
 for _, spec in pairs(specs) do
            local creatures = Tile(nextPos):getCreatures(specs)
            -- if creature == nil then return false end
            for k, creature in pairs(creatures) do
                if creature:isPlayer() then
                print(" ..creature.. ")
                    creature:teleportTo(mietek.teleportWhenHitPlayer)
                end
            end
            end
 
change
Lua:
 for _, spec in pairs(specs) do
            local creatures = Tile(nextPos):getCreatures(specs)
            -- if creature == nil then return false end
            for k, creature in pairs(creatures) do
                if creature:isPlayer() then
                print(" ..creature.. ")
                    creature:teleportTo(mietek.teleportWhenHitPlayer)
                end
            end

to

Code:
if(specs) then
 for _, spec in pairs(specs) do
            local creatures = Tile(nextPos):getCreatures(specs)
            -- if creature == nil then return false end
            for k, creature in pairs(creatures) do
                if creature:isPlayer() then
                print(" ..creature.. ")
                    creature:teleportTo(mietek.teleportWhenHitPlayer)
                end
            end
            end
have this:

Lua:
scriptInterface: [Main Interface]
scriptId: [(Unknown scriptfile)]
timerEvent: [in a timer event called from:]
 callbackId:[]
function: []
error [/home/ots/data-otservbr-global/scripts/custom/effectt.lua:106: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
        [C]: at 0x55a46eb07da0
        [C]: in function 'pairs'
        /home/ots/data-otservbr-global/scripts/custom/effectt.lua:106: in function </home/ots/data-otservbr-global/scripts/custom/effectt.lua:96>]
 
have this:

Lua:
scriptInterface: [Main Interface]
scriptId: [(Unknown scriptfile)]
timerEvent: [in a timer event called from:]
 callbackId:[]
function: []
error [/home/ots/data-otservbr-global/scripts/custom/effectt.lua:106: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
        [C]: at 0x55a46eb07da0
        [C]: in function 'pairs'
        /home/ots/data-otservbr-global/scripts/custom/effectt.lua:106: in function </home/ots/data-otservbr-global/scripts/custom/effectt.lua:96>]

Lua:
function Position:sendDistanceAnimateEffect(toPosition, distanceEffect, queueEffect)
  local pos       = Position(self) -- copy
  local distance  = self:getDistance(toPosition)
  local direction = self:getDirection(toPosition)
  
  for i = 1, distance do
    local nextPos = Position(pos) -- copy
    nextPos:getNextPosition(direction)
    
    addEvent(function()
      pos:sendMagicEffect(queueEffect)
      pos:sendDistanceEffect(nextPos, distanceEffect)
      local nextPosTile = Tile(nextPos)
      if nextPosTile then
        for _, creature in ipairs(nextPosTile:getCreatures() or { }) do
          if creature:isPlayer() then
            creature:teleportTo(mietek.teleportWhenHitPlayer)
          end
        end
      end
    end, 125 * i)
    
    pos = nextPos
  end
end

Note: I didn't understand what you're trying with that code, neither why you're attaching it to Position class something that will probably be used only once.
 
Last edited:
Solution
Lua:
local rangeX, rangeY = 5, 5

function Position:sendDistanceAnimateEffect(toPosition, distanceEffect, queueEffect)
  local pos       = Position(self) -- copy
  local distance  = self:getDistance(toPosition)
  local direction = self:getDirection(toPosition)
 
  for i = 1, distance do
    local nextPos = Position(pos) -- copy
    nextPos:getNextPosition(direction)
   
    addEvent(function()
      pos:sendMagicEffect(queueEffect)
      pos:sendDistanceEffect(nextPos, distanceEffect)
     
      for _, spec in ipairs(Game.getSpectators(Position(1115, 167, 6), false, false, rangeX, rangeY)) do
        local nextPosTile = Tile(nextPos)
        if nextPosTile then
          for _, creature in ipairs(nextPosTile:getCreatures() or { }) do
            if creature:isPlayer() then
              creature:teleportTo(mietek.teleportWhenHitPlayer)
            end
          end
        end
      end
    end, 125 * i)
   
    pos = nextPos
  end
end

Note: I didn't understand what you're trying with that code, neither why you're attaching it to Position class something that will probably be used only once.
this is the solution to my problem
 
Back
Top