Page 1 of 3
Enemy/AI system {Still need help D:}
Posted: Wed Dec 21, 2011 3:35 pm
by MP6767
I've tried many things to make sprites move across the gamefield and attack, but they don't even show up. Could anyone show me an example?
EDIT 12/23/11: Still need help: When using
Code: Select all
function zombieType:update(dt)
for i, zombieType in pairs(zombieType) do
zombieType.x = math.random(0,32)
zombieType.y = math.random(0,32)
end
end
it just gives a syntax error saying "attempt to index local zombieType (A function value).
Anyone have any ideas on how to fix it?
Re: Enemy/AI system
Posted: Wed Dec 21, 2011 3:39 pm
by Nixola
Can you show us your "many things", so that we can correct you?
Re: Enemy/AI system
Posted: Wed Dec 21, 2011 3:50 pm
by MP6767
Alright, here's the code for a zombie that I used, from another thread...
Code: Select all
function zombieType:create(v)
local instance = {}
setmetatable(instance, {__index = self})
instance:reset(v)
return instance
end
function zombieType:reset(v)
v = v or {}
self.x = v.x or 300
self.y = v.y or 500
self.speed = v.speed or 100
self.color = v.color or { 255, 255, 255 }
self.health = v.health or 10
self.pic = v.img or zombImg
self.reach = v.reach or 55
self.damage = v.damage or 2
end
function zombieType:update(dt)
end
function zombieType:draw()
love.graphics.draw(zomb, math.random(350), math.random(400), 0, 4, 4)
end
I've also tried using math.random to pick a place for them to spawn, pick a place for them to move to, and to dictate the amount of damage they deal, but that just gave me a bunch of syntax errors.
Re: Enemy/AI system
Posted: Wed Dec 21, 2011 3:59 pm
by tentus
Without your whole code we can't help you much, but offhand I will point out that you are drawing your zombie at a random location: since you choose the position again for each frame, it may just be that you can't see your zombie because they move to a new location every single frame.
Re: Enemy/AI system
Posted: Wed Dec 21, 2011 4:04 pm
by MP6767
tentus wrote:Without your whole code we can't help you much, but offhand I will point out that you are drawing your zombie at a random location: since you choose the position again for each frame, it may just be that you can't see your zombie because they move to a new location every single frame.
Re: Enemy/AI system
Posted: Wed Dec 21, 2011 6:46 pm
by Robin
You draw each zombie on a random location:
Code: Select all
love.graphics.draw(zomb, math.random(350), math.random(400), 0, 4, 4)
That should be
Code: Select all
love.graphics.draw(zomb, self.x, self.y, 0, 4, 4)
Re: Enemy/AI system
Posted: Wed Dec 21, 2011 8:45 pm
by MP6767
Still getting an error on line 125, line 125 contains what you told me to put in.
Code: Select all
function zombieType:draw()
love.graphics.draw(zomb, self.x, self.y, 0, 4, 4)
end
Re: Enemy/AI system
Posted: Wed Dec 21, 2011 9:17 pm
by Robin
What is the error?
Re: Enemy/AI system
Posted: Wed Dec 21, 2011 9:32 pm
by MP6767
Incorrect parameter type: expected userdata
Re: Enemy/AI system
Posted: Wed Dec 21, 2011 9:37 pm
by Robin
That's more like it.
You made a mistake with the variable name. You used zomb, while it should be zombie.