1. Hey,

How might I go about making bullets?
I've made a bullet class, but I can't figure out how I go about using them, as in, editing them once they're made.

I have:
Code:
Bullet = {}
Bullet.new = function(x, y)
local self = {}
local x = x or love.mouse.getX()
local y = y or love.mouse.getY()

self.getX = function() return x end
self.getY = function() return y end
self.setX = function(val) x = val end
self.setY = function(val) Y = val end
return self
end
Obviously I can do a
Code:
if fire then
bullet = Bullet.new(x, y)
end
But how can I make more than 1 and be able to modify its position?

I tried something like
Code:
bullets = {}
for i = 0, 20 do
bullets[i] = Bullet.new()
end
for i = 0, 20 do
bullets[i].setX(500)
end
but that didn't seem to work :/

Any help?

Thanks

2. "love.mouse.love.mouse.getX()"

what are you

what
Funny x 5 (list)

3. That's not the idiomatic way to handle classes in Lua. Look up metatables.
Agree x 1 (list)

4. surely that doesn't work?

edit: automerge etc.

5. In fact, your code doesn't even make sense. Try this:

Code:
Bullet_mt = {}
Bullet_mt.getX = function(self)
return self.x
end
Bullet_mt.getY = function(self)
return self.y
end
Bullet_mt.setX = function(self, x)
self.x = x
end
Bullet_mt.setY = function(self, y)
self.y = y
end

function NewBullet(x, y)
local self = {}
setmetatable(self, Bullet_mt)

self.x = x or love.mouse.getX()
self.y = y or love.mouse.getY()

return self
end
Then you can use this syntactic sugar to invoke the functions:

Code:
local bullet = NewBullet(0, 0)
-- x:y(z) is the same as y(x, z)
bullet:setX(100)
print bullet:getX()

6. "love.mouse.love.mouse.getX()"

what are you

what
Sorry, I started writing it out manually, then copy pasted it in forgetting to remove the first love.mouse. Its not like that in the code.

In fact, your code doesn't even make sense. Try this:

Code:
Bullet_mt = {}
Bullet_mt.getX = function(self)
return self.x
end
Bullet_mt.getY = function(self)
return self.y
end
Bullet_mt.setX = function(self, x)
self.x = x
end
Bullet_mt.setY = function(self, y)
self.y = y
end

function NewBullet(x, y)
local self = {}
setmetatable(self, Bullet_mt)

self.x = x or love.mouse.getX()
self.y = y or love.mouse.getY()

return self
end
Then you can use this syntactic sugar to invoke the functions:

Code:
local bullet = NewBullet(0, 0)
-- x:y(z) is the same as y(x, z)
bullet:setX(100)
print bullet:getX()
Ok, thanks. But I still don't get how I'd go about using multiple bullets.

7. Ok, thanks. But I still don't get how I'd go about using multiple bullets.
You're using them correctly, but it didn't work before because the class itself was broken.
Friendly x 1 (list)

8. You're using them correctly, but it didn't work before because the class itself was broken.
Excellent, thank you very much, everything works now :)