Log In  

So I have this problem that keeps coming up. I'm working on my game Gravitas, and am trying to move objects over to tables, using modified versions of the code Davbo provided in this thread(https://www.lexaloffle.com/bbs/?tid=31392). One problem that I am having, however, is when I try to do logic with this type of table code,

enemyx = {30,40,50,60,70,80,90,100,25,35,45,55,65,75,85,95,105,115}
enemyy = {10,10,10,10,10,10,10,10 ,20,20,20,20,20,20,20,20,20 ,20 }

enemies = {}

function createenemy(x,y,z,w)
 enemy = {}
 enemy.x = x
 enemy.y = y
 enemy.class = z
 enemy.laserct = w
 add(enemies,enemy)
end

enemyct = 0

function enemyspawn(x,y)
 if enemyct <= 17 then
  createenemy(enemyx[enemyct],enemyy[enemyct],1)
  enemyct = enemyct+1
 end
 for enemy in all(enemies) do
  if 10 > enemy.y then
   del(enemies,enemy)
  end
 end
end

I have this problem where when drawing the enemy, a "ghost" enemy appears at (0,0). This overlaps with scores, and it's not fun. I'm not sure why, as every enemy drawn is at points from the enemyx,enemyy tables.

So to get around this, I added in the "if 10 < enemy.y then..." which ends up throwing me the "attempt to compare number with nil error. I've solved this in the past by just starting the object off at the y position that it is set at (ex. enemy.y = 10) but this doesn't work if enemies stored on the same table are at different y positions.

I've looked all over, and any help would be appreciated.

EDIT: I should note that I have had the "ghost" issue before, and somehow managed to fix it, and neither going through my code or my videos talking about the code managed to yield any results.

Thanks :)

P#55540 2018-08-23 13:18 ( Edited 2018-08-23 21:18)

Having the draw code would help...

P#55558 2018-08-23 16:14 ( Edited 2018-08-23 20:14)

Does your Code change the Variable "enemyct" before using it in the "enemyspawn"-function? If not, than that's the Problem.

In Lua (and so in PICO-8), an Array starts with "1", not with "0". If you try to get the Value of a "Zero"-Element, it will return "nil". Under certain circumstances, "nil" can be interpreted as Value 0, like X- and Y-Coordinates...

P#55566 2018-08-23 16:43 ( Edited 2018-08-23 20:44)

@Astorek

That part fixed the ghost sprite. Thanks a ton for that. I looked around for so long, and that was the simplest thing.

P#55573 2018-08-23 17:18 ( Edited 2018-08-23 21:18)

[Please log in to post a comment]