I’ve been building up a game for almost a week now, and so far things have been great.
However, I sometimes stumble into some things that look easy, but my inexperience holds me back
In my game, I have to spawn objects regularly, but they must hold a variable because, with each hit, they will award more points when they are destroyed. However, with the LUA not being very OOPish, I can’t seem to make this happen.
Should I create instances of the object with different names? Would that work? If so, how can I do this?
Can you guys please enlighten me?
Thanks in advance!! [import]uid: 11130 topic_id: 3766 reply_id: 303766[/import]
jmp909 saves my day once again!
I’ll read this, but it looks easy enough.
Quick question: Can I do this without “requiring” a class? I mean, doing everything in the main.lua?
Not that its a problem, just trying to understand it
The way I have been doing a basic OO structure is like this:
For examples sake I have called this “ball.lua”
module(..., package.seeall)
function new(name)
local self = {} -- this is just a blank table but it could be a Corona display object like display.newImage("ball.png")
self.name = name
function self:print()
print(self.name)
end
return self
end
Then after including this in for instance your main.lua file you will be able to do things like this:
[code]
local ball = require(“ball.lua”)
local ball1 = ball.new(“Ball1”)
local ball2 = ball.new(“Ball2”)
local ball3 = ball.new(“AnyNameYouWant”)
ball1:print() – Prints “Ball1”
ball2:print() – Prints “Ball2”
ball3:print() – Prints “AnyNameYouWant”