简体   繁体   English

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

[英]Attempt to index field “?” (nil value)

hey guy i am new to corona and i am trying to spawn some objects that fall out of the sky on to the ground. 嗨,我是电晕的新手,我正尝试产生一些从天上掉下来的东西落到地面上。 i have posted this same code already the person who answered don't answer the question fully. 我已经发布了相同的代码,回答的人没有完全回答问题。 i need help with this so i could get my game on track thanks guys. 我需要帮助,以便让我的比赛顺利进行,谢谢大家。 some one please tell me why i am getting "Attempt to index field "?" (nil value)" i know something doesn't exist. 有人请告诉我为什么我得到“试图索引字段“?”(零值)”我知道不存在的东西。 also the code that is giving me this problem is "object[objectTag].x = 30+mRandom(320)" i try to comment it out and try to work without it but the error goes to the next line. 也是给我这个问题的代码是“ object [objectTag] .x = 30 + mRandom(320)”,我尝试将其注释掉,并尝试在没有它的情况下工作,但错误转到下一行。 can someone help. 有人可以帮忙吗? thanks 谢谢

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)

Can you use this code block to see if there is a problem with image loading 您可以使用此代码块查看图像加载是否存在问题

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM