Hi people,
I have a question for the die-hard coders out there: using OOP or pseudo-OOP (like prototyping) in Lua, is it possible (and how) to have different instances of objects (creating from different modules) to have access to eachother’s public methods and properties, without resorting to a lot of global scoping?
Let me give an example to clarify:
- I spawn a hero character from my main.lua, using a module called hero.lua (where a constructor method returns an instance of the hero class).
- I spawn a boss character from my main.lua, using a module called boss.lua (where a constructor method returns an instance of the boss class).
- The boss character has a function that spawns a bullet every second, using a module called bullet.lua (where a constructor method returns an instance of the bullet class).
Now I want the bullet objects (instances of the bullet class) to check if they are within a certain distance of the hero object every frame (to kill the hero if they are close enough!) but this means that I need to write code in the bullet.lua module that “has access to” the hero object. And this is where I’m stumbling and can’t seem to get things to work. I’ve tried requiring the “hero.lua” module in my “bullet.lua” module, but somehow this seems to give the bullets knowledge about the abstract class “hero”, but not access to my specific hero object. And how could it? The hero object’s handle is declared in main.lua so there’s no way for bullet.lua to know the name of the hero instance unless I make it a global, right? And that’s something I really want to avoid since so much game logic will operate on the hero.
Sheesh! I know this isn’t an easy question, but I’d appreciate the help even more! 
Cheers,
Thomas [import]uid: 70134 topic_id: 28766 reply_id: 328766[/import]