Hi, another table question. Im getting a basic understanding but am struggling with the below so all help appreciated.
Ok so I have a touch event to fire my weapons, I have various classes for each weapon. Instead of using IF statements to check the variable on fire I would like to use the variable (number) to call the particular class.
Here is the function working, it only calls one class (Missile):
function fireMissile(event)
if event.phase == "began" and control == false then
local i = math.random(2)
audio.play(pistolSounds[2])
-- create missile, aim at event target, spawn from character
local missile = Missile.new(event.x, event.y, balloon.x, balloon.y)
missiles:insert(missile)
setMass(-1)
setScore(1)
end
end
Here is what im kinda looking for but im not sure how I can pass all the arguments to the class without passing them when the tables created?:
local weapons = {}
local grade1 = require("Bullet")
local grade2 = require("Missile")
weapons[1] = grade1.new() --reference to instaniated object without variables cause error
weapons[2] = grade2.new() --reference to instaniated object without variables cause error
local grade = 2
function fireMissile(event)
if event.phase == "began" and control == false then
local i = math.random(2)
audio.play(pistolSounds[2])
-- create projectile, aim at event target, spawn from character
local missile = weapons[grade].(event.x, event.y, balloon.x, balloon.y)
missiles:insert(missile)
setMass(-1)
setScore(1)
end
end
Basically I want to store a reference to the class without creating it until the event is fired. All insight really helps. Thanks. [import]uid: 118379 topic_id: 21204 reply_id: 321204[/import]