Another tables question - calling class with event arguments

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]

answered my own question

[code]
local weapons = {}
weapons[1] = require(“Bullet”) --reference to instaniated object
weapons[2] = require(“Missile”) --reference to instaniated object

local grade = 2

function fireMissile(event)
if event.phase == “began” and control == false then

local i = math.random(2)
audio.play(pistolSounds[2])

–make object 1 do something

– create missile, aim at event target, spawn from character
local missile = weapons[1].new(event.x, event.y, balloon.x, balloon.y)
missiles:insert(missile)

setMass(-1)
setScore(1)
end
end

[/code] [import]uid: 118379 topic_id: 21204 reply_id: 83968[/import]

answered my own question

[code]
local weapons = {}
weapons[1] = require(“Bullet”) --reference to instaniated object
weapons[2] = require(“Missile”) --reference to instaniated object

local grade = 2

function fireMissile(event)
if event.phase == “began” and control == false then

local i = math.random(2)
audio.play(pistolSounds[2])

–make object 1 do something

– create missile, aim at event target, spawn from character
local missile = weapons[1].new(event.x, event.y, balloon.x, balloon.y)
missiles:insert(missile)

setMass(-1)
setScore(1)
end
end

[/code] [import]uid: 118379 topic_id: 21204 reply_id: 83969[/import]