Hey Iarwain. I have another quick question for you. We want some of our objects - namely the enemies - to have custom fields representing max health and damage taken. The question is: how do we make these custom fields (preferably in the INIs)?
The biggest problem is that every enemy will be created from config with the same object. Is there a way to access these fields from the pointer to a created object? Is there a better way to create fields like this in general?
Comments
I guess you need something like this:
Basically you can just add your custom fields without any problems:
And later you can Get/Set them using the functions provided in the orxConfig space.
HTH,
Alex
For each enemy created with the orxObject_CreateFromConfig function, each enemy will have 100 HP. What's the best way to keep track of each enemy's individual HP? I don't think I can keep using the orxConfig_Get/SetListString functions in that case.
EDIT: And what's UserData, and how do I use it? I think it might be just what I'm looking for.
My Get/Set list example is just a quick copy/paste from my project. I'm sorry if that confused you :-)
Good luck!
I give you some tricks.
orxConfig_XXX functions does "what you want"
I think the best example for your problem is Scroll (you can find informations about it in an another post).
Scroll use a combination of orxConfig_XXX function and orxObject_SetUserData to achieve exactly what you want.
I'll try to explain, but I really recommend you to check out Scroll and observe the Iarwain's code
Scroll define a C++ class, called ScrollObject. An instance of ScrollObject refer to an object in the config module.
Each instance of a Scroll object use a base section in the config, the same as yours (the section that describe your object), used and shared by all instances.
But in addition, a scroll object create a "unique" section in the config module (this unique name is generated by scroll). So, each instance can keep values in it's "unique" section.
The C++ instance of a scroll object is linked to its corresponding orxOBJECT using the function orxObject_SetUserData. So, when you have an orxOBJECT*, you can retreive the C++ instance by using the orxObject_GetUserData() function.
I know my explanation are not very good and same for my english, hope that can help ... ^^
EDIT: Right after saying that, I got it to load. Ignore that, I'm going to try this game out now.
Orx uses it to drive the creation of some structures (sound, fx, graphics, objects, ...) and so can the user do on his end.
The concept of unique ID for objects is implemented in Scroll, not in orx, but it's easy to roll your own if you need it.
Here's a small example of how to achieve HP for enemies. Of course you can use C++ classes and use inheritance and whatnot, it's really a minimal example to show how to use the user data part of objects.
I made use of this tonight.
In my level select screen, I wanted to create a large number of similar icons to represent the different levels. I preferred to define only one icon object in the config, of course, but I needed to track which icon selects which level when tapped.
So the level number is generated and stored in a config for each icon as it is created and the config section name is stored as the user data for the icon.
But if I understand correctly, if you wanted it you could have eliminated the need of using the UserData field altogether.
Something like:
I was looking for a SetName function to pick the particular icon, but SetParent should work for this and should fit right in with my architecture.
Off-topic but related, I have used the config system with great success for creating a kind of menu/dialog manager for my game. I have a "Type" property to define a button or label, for example. And I set properties like "To"/"From" or "Action"/"Target" in config.
So in code, I can perform functions like switching between menus and making a mouse click on a menu button increase the value of a label.
And the code is abstract, so it doesn't have to know anything about the specific menu it's using.
If you ever feel like it, that could be a nice thing to have in the wiki, in the community tutorial section.
That reminds me of a more limited system I made for buttons in ScrollEd where buttons are generic config section with "IsButton"/"Action"/"HighLight" fields.
The "Action" field is then used to set a virtual input with orxInput_SetValue() when the button is clicked.
This way one can add, at will, buttons or any key shortcuts to any "Action" recognized by the editor without having to touch the code.
The main reason I have not written any tutorials yet is everything is still evolving so quickly in my project
But we are getting close to a beta, so things are stabilizing a bit and I might write something then.
Which reminds me, I need to start a thread in the projects section...
Looking forward to learning more about your project.