尝试索引字段“?” (零值)

时间:2013-07-15 17:20:16

标签: android object corona

嘿,我是新来的日冕,我正试图将一些落在天空之外的物体放到地上。我已经发布了相同的代码已经回答的人没有完全回答这个问题。我需要这方面的帮助,所以我可以让我的游戏在轨道上谢谢你们。请告诉我为什么我会“尝试索引字段”?“(零值)”我知道某些东西不存在。同样给我这个问题的代码是“object [objectTag] .x = 30 + mRandom(320)”我尝试将其注释掉并尝试在没有它的情况下工作,但错误转到下一行。有人可以帮忙吗谢谢

local  mRandom = math.random
local   objects = {"rocket02" ,"rocket01","coin01"}
local objectTag = 0
local object = {}

  local   function spawnObject()
  objectTag = objectTag + 1
  local objIdx = mRandom(#objects)
  local objName = objects[objIdx]
  object[objectTag]  = display.newImage("image/object_"..objName..".png")
  *object[objectTag].x = 30+mRandom(320)
  object[objectTag].y = 200
  object[objectTag].name = objectTag*
  print(objectTag)
end
timer.performWithDelay(1,spawnObject,3)

1 个答案:

答案 0 :(得分:0)

您可以使用此代码块查看图像加载是否存在问题

local  mRandom = math.random
local   objects = {"rocket02" ,"rocket01","coin01"}
local objectTag = 0
local object = {}

  local   function spawnObject()
  objectTag = objectTag + 1
  local objIdx = mRandom(#objects)
  local objName = objects[objIdx]
  object[objectTag]  = display.newImage("image/object_"..objName..".png")
  if object[objectTag] ~= nil then
    print( "Image succesfully loaded." )
  else
    print( "Image couldn't be found." )
  end
  *object[objectTag].x = 30+mRandom(320)
  object[objectTag].y = 200
  object[objectTag].name = objectTag*
  print(objectTag)
end
timer.performWithDelay(1,spawnObject,3)