简体   繁体   中英

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. 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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