I'm creating a game engine, and in my editor, there needs to be a way to create objects. These objects will be assigned a name and other properties based on the user's input in a bunch of textboxes. What I need to do is create an object with the name that the user puts into the textbox. Additionally, I need to store this name so that when everything needs to be rendered, code for each object doesn't need to be added, only a method that cycles through the array and renders everything.
Letting the user access the variables is a very unsafe way to program, I don't even know if it is possible. (Maybe with an eval function)
You don't want this bad design in your engine, believe me...
Why don't just create an ArrayList with the type of your Objects?
If you don't understand this then show how your object is made (Defined, initialised, name, ...) and I'll show an exact example how you should do it.
Here is an example I found: http://www.java2s.co...looptocheck.htm
You can add your objects instead of the strings.
I need to store this name so that when everything needs to be rendered
You could create a class RenderObject or NamedObject that inherits your Object and adds a name field to it, then use these objects to add to your array.
Or when you don't have objects you could make an ArrayList of strings.
--- My post is a bit bloated I think, hope you understand it, I'm writing a game engine too since yesterday.
Edited by TomWij, 22 June 2008 - 02:56 PM.