2013-03-22 3 views
6

나를 미치게 만드는 오류에 대해 도움을 요청할 것입니다.LUA 및 코로나 오류 : 메서드 호출 '시도'(무제한 값) - 미친 듯이 뛰기

오 ... 나는

나는 선박의 인스턴스를 생성하고 ... BTW 코로나 SDK로 LUA를 사용하고 있습니다. 우주선이 인스턴스화 중이고 그 속성에 액세스 할 수 있지만 어떤 방법으로도 액세스 할 수 없습니다 !!

require('gameConf') 

spaceShip = {} 
spaceShip.__index = spaceShip 

function spaceShip:New(posX, posY, width, height) 
    local _spaceShip = nil 
    _spaceShip = {} 
    setmetatable(_spaceShip, spaceShip) 

    _spaceShip = display.newRect(posX - width/2, posY - height/2, width, height) 
    _spaceShip:setFillColor(140, 140, 140, 0) 
    _spaceShip.width = width 
    _spaceShip.height = height 

    local shipShape = { -width/2, -height/2, width/2, -height/2, width/2, height/2, -width/2, height/2 } 
    local shipShapeMaterial = { density = 1.0, friction = 1.0, bounce = 0.0 , shape = shipShape} 

    local shipMotor = { -width/2, height/3, width/2, height/3, width/2, height/2, -width/2, height/2 } 
    local shipMotorMaterial = { density = 1.0, friction = 1.0, bounce = 0.0 , shape = shipMotor} 

    physics.addBody(_spaceShip, shipShapeMaterial, shipMotorMaterial) 

    return _spaceShip 
end 

function spaceShip:log() 
    print("ship") 
end 

function spaceShip:applyFrontImpulse() 
    local angle = math.rad(self.rotation) 
    local xComp, yComp = math.cos(angle), -math.sin(angle) 
    local forceMag = 2 

    self:applyLinearImpulse(forceMag * xComp, forceMag * yComp, self.x, self.y) 
end 

및 main.lua의 일부

require('camera') 
require('gameConf') 
require('meteor') 
require('spaceShip') 

-- Add Physics 
local physics = require("physics") 
physics.start() 
physics.setDrawMode("hybrid") 
physics.setGravity(0, 0) 

-- Load camera 
local camera = camera:New() 

-- Containers 
meteorManager = {} 
shipManager = {} 

-- Load Vector class 
vector = require "vector" 

-- Create one ship 
local myShip = nil; 
myShip = {} 
myShip = spaceShip:New(600, 200, 30, 60) 
table.insert(shipManager, myShip) 
camera:insert(myShip) 
myShip:log() <----- HERE IS THE ERROR 

rest of the code... 

터미널의 오류는 다음과 같습니다 :

spaceShip.lua을 : 코드에 따라, 나는 무엇을 해야할지하지 않습니다

2013-03-21 19:18:15.736 Corona Simulator[48347:707] Runtime error: 
2013-03-21 19:18:15.737 Corona Simulator[48347:707] ...t/iOS/Deep Space Harvest/Deep Space Harvest/main.lua:28: attempt to call method 'log' (a nil value) 
stack traceback: 
[C]: in function 'log' 
...t/iOS/Deep Space Harvest/Deep Space Harvest/main.lua:28: in main chunk 

답변

6

이 조각 때문에이 문제가 의심됩니다.

_spaceShip = {} 
setmetatable(_spaceShip, spaceShip) 

_spaceShip = display.newRect(posX - width/2, posY - height/2, width, height) 

_spaceShip에 메타 테이블을 설정했지만 새 값이 할당되었습니다. 이 시점에서 할당 한 새 값에는 값 (변수가 아님)에있는대로 설정 한 메타 테이블 연결이 없습니다.

setmetatable_spaceShip = display.newRect... 이후로 이동하십시오.

+0

예! 당신 말이 맞아요! 나는 디스플레이를 사용하여 메타 테이블을 정의하는 작업을 끝냈습니다. 수정하려면 디스플레이 spaceShip.body =을 만들었습니다. 이제 작동했습니다! 고맙습니다! –

+0

도와 드릴까요? http://stackoverflow.com/questions/15716914/object-assignment-lua – user2136963

관련 문제