Enemy/AI system {Still need help D:}

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
MP6767
Prole
Posts: 16
Joined: Wed Dec 21, 2011 12:18 am

Enemy/AI system {Still need help D:}

Post 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?
Last edited by MP6767 on Sat Dec 24, 2011 5:51 am, edited 2 times in total.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Enemy/AI system

Post by Nixola »

Can you show us your "many things", so that we can correct you?
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
MP6767
Prole
Posts: 16
Joined: Wed Dec 21, 2011 12:18 am

Re: Enemy/AI system

Post 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.
User avatar
tentus
Inner party member
Posts: 1060
Joined: Sun Oct 31, 2010 7:56 pm
Location: Appalachia
Contact:

Re: Enemy/AI system

Post 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.
Kurosuke needs beta testers
MP6767
Prole
Posts: 16
Joined: Wed Dec 21, 2011 12:18 am

Re: Enemy/AI system

Post 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.
Attachments
main.lua
Main code :o
(3.8 KiB) Downloaded 179 times
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Enemy/AI system

Post 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)
Help us help you: attach a .love.
MP6767
Prole
Posts: 16
Joined: Wed Dec 21, 2011 12:18 am

Re: Enemy/AI system

Post 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
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Enemy/AI system

Post by Robin »

What is the error?
Help us help you: attach a .love.
MP6767
Prole
Posts: 16
Joined: Wed Dec 21, 2011 12:18 am

Re: Enemy/AI system

Post by MP6767 »

Incorrect parameter type: expected userdata
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Enemy/AI system

Post by Robin »

That's more like it.

You made a mistake with the variable name. You used zomb, while it should be zombie.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 4 guests