Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
manage objects automatically
#21
(01-16-2024, 01:48 PM)aliensoldier Wrote: Hello Marcus, have you looked at the last example I gave you to see if everything is correct or if there is something to correct.

Sorry for taking so long again, but I'm looking at your code right now.

It looks good, so I say start making a game already Smile 

I noticed that when you create a bullet, you use Father_getId to store the enemy sprite in the bullet. In a game there would probably be multiple enemies that appear and disappear constantly. In that case you would need a function similar to Father_getId that returns a list (an array) with all active sprites that use the specified id, and you would need to call it in the bullet's update function.

Also, right now the only sprite that has an id variable is the enemy. The enemy happens to be the first sprite that you send to Father_Add, and therefor the code works as intended. But if you replace:

(example-father.n7)
Code:
Father_Add(Enemy(320,100))
Father_Add(Player(320,390))

with

Code:
Father_Add(Player(320,390))
Father_Add(Enemy(320,100))

the game will throw a runtime error when you try to shoot:

Code:
(renv) father1.n7:36, bullet1.n7:14, player1.n7:48,21, father1.n7:47, example-father.n7:19: runtime error: Identifier 'id' not found (BC_MLOAD_S)

In case you didn't know, "father1.n7:36, bullet1.n7:14, player1.n7:48,21, father1.n7:47, example-father.n7:19" is a stack-trace. The crash occurred on line 36 in father1.n7 in a function called from line 14 in bullet1.n7, and so on. What "Identifier 'id' not found" means is that it couldn't find a variable named 'id' in a table. BC_MLOAD_S was the "assembler" instruction that threw the error (it's useful info meant for me).
The solution is to add an id variable to player and bullet too.
Reply
#22
Quote:I noticed that when you create a bullet, you use Father_getId to store the enemy sprite in the bullet. In a game there would probably be multiple enemies that appear and disappear constantly. In that case you would need a function similar to Father_getId that returns a list (an array) with all active sprites that use the specified id, and you would need to call it in the bullet's update function.


Can you show me what the code would be like, I can't get it to work.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)