Function pointer by name?

BlitzMax Forums/BlitzMax Programming/Function pointer by name?

pilgrim(Posted 2009) [#1]
I've scoured the forum for any topics that already addressed this question, so apologies if this has already been covered...


BIG PICTURE: Keeping game specific code completely seperate from the game engine code

SETUP: I am loading a text file (game specific) that contains data for entities within a game environment. The engine creates the entities based on this text data. Each entity is given a unique name, a string, which is stored in the engine for referencing the entity's data. I have a .bmx file that contains game specific types derived from an engine base type that are the entities in the engine. Each entity type also contains a function called 'new*EntityName*Func()' which just creates a new instance of this particular type. Example: an entity named "Alien" whould have a member function in it's type called 'newAlienFunc()'.

PROBLEM: I am trying to build the name of this member function when my text file is parsed and point a function pointer to it. This will enable the engine code that creates new entities to simply call a generic 'newEntityFunc()' which would actually point to a unique function for each entity type based on run-time data. If my memory serves, this was not a problem in a C implementation of this engine - hoping someone has insight into this area of BlitxMax.

Thanks in advance!


N(Posted 2009) [#2]
Create a map of the functions and get it from there, either that or use the factory pattern to devise something.


ImaginaryHuman(Posted 2009) [#3]
Yah put pointers to the functions in an array and store the index instead of the name.