This is not directly related to your radar question, but it seems you could use a little help to structure your code. For the moment it looks like you are not able to access all info from different objects when you want to.
The easiest way to go about this is:
-
Create a “master” module or object in main.lua - i always call this object appEngine
-
Let appEngine create the objects needed for a level for you, using separate modules of course.
-
When you create multiple asteroids, create an object or module “above” the single asteroids called “asteroidManager” manager or something like that. “asteroidManager” needs a variable table called “asteroidList” containing the multiple asteroids. This helps tremendously in organizing your code.
-
Everytime you create an object, make sure you pass the “parent” object to it as a variable. This way, every object will be able to “talk to” or access the objects above it in the hierarchy.
An example: let’s say you create “appEngine”, appEngine create “asteroidManager”, and this asteroidManager creates multiple "asteroid"s kept in a table.
If you pass “parent” objects to child objects and store them in a variable call self.super, every asteroid will be able to talk to the asteroidManager by using “self.super”, and to “appEngine” by using “self.super.super”
Then, if the ship is also a child of “appEngine”, asteroids can talk to the ship (or see it’s x and y variable) by using “self.super.super.ship.x” for example.
The other way around, the ship’s super is appEngine, so a ship can talk to the first asteroid in asteroidManager’s list by using “self.super.asteroidManager.asteroidList[1]”
Does this make sense, or is it complete nonsense to you?