manage objects automatically - Printable Version +- NaaLaa (https://www.naalaa.com/forum) +-- Forum: NaaLaa (https://www.naalaa.com/forum/forum-1.html) +--- Forum: NaaLaa 7 Questions (https://www.naalaa.com/forum/forum-3.html) +--- Thread: manage objects automatically (/thread-2.html) |
RE: manage objects automatically - Marcus - 11-16-2023 (11-14-2023, 05:12 PM)aliensoldier Wrote: I have created two examples based on the one you have shown me of oop, one with a list and the other without a list Sorry for the delay, got busy yesterday, but I've had a look at your code now I replaced Code: free deadList[i] Code: free val fatherList, deadList[i] The new line removes the object in deadList from fatherList. That is, 'free val x, y' removes any occurrence of y from the array/table x and re-indexes the array (removes any holes). Code: function Father_Update() You should never use 'free' when working with arrays. Always use 'free val' (remove any occurrence of a value) or 'free key' (remove an index/key and its value). RE: manage objects automatically - aliensoldier - 11-16-2023 Thank you very much for all the help, I really liked all the examples and I have learned a lot. RE: manage objects automatically - aliensoldier - 11-29-2023 Hello Marcus. I have prepared another, slightly more elaborate example. I would like you to look at the father1 file and tell me if it is programmed correctly or if there is something to change or correct. You can also look at the rest, greetings. RE: manage objects automatically - aliensoldier - 12-09-2023 Hello Marcus. Have you looked at the code that I wrote a couple of weeks ago, I want to know if it is correct to start programming a small game. RE: manage objects automatically - Marcus - 12-09-2023 Ah, sorry, I started looking at it when I was in a rush right after you posted it, but I got confused about something and then forgot about it I'll try and have a look at it tomorrow! RE: manage objects automatically - Marcus - 12-18-2023 I'm terribly sorry for still not having had a look at your code. It's christmas times, and I barely have the time to start my computer. But if it it works, it works. And no matter how well it works, you'll find things and bugs while actually writing a game using the code. So start coding and see what happens I will review the code eventually, when things get more calm over here. RE: manage objects automatically - Marcus - 12-18-2023 I had a short look now, and I'm a bit confused Let's focus on the main file, example-father, for now: Code: while not keydown(KEY_ESCAPE,true) Here you create a new father object every time you call Father(), which is a bit "strange" and not optimal. The problem is that you have made the "base class", Father, serve as a sprite manager. If I were you, I would remove the functions Add, Update_all, Draw_all, Destroy and Clear from Father and put them in regular functions, or create another "class" (a sprite manager) whose only job is to manage a list of sprites. I've attached a new example-father.n7 and father1.n7 where I've made the change that I suggested. Every function that deals with the sprite list (fatherList) are now regular functions. I didn't remove the functions from the father "class", but they now call the independant functions. RE: manage objects automatically - aliensoldier - 12-20-2023 I'm going to look at the corrections you've made. RE: manage objects automatically - aliensoldier - 12-21-2023 I have added all the corrections that you have mentioned and I have added a new function called Father_getId(), to obtain the id of each object and be able to access its properties. Tell me if everything is correct and I'll start with my first game. RE: manage objects automatically - aliensoldier - 01-16-2024 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. |