Given that you cannot change the fundamental architecture (which is horrible, btw):
Another possibility would be giving the base class a std::map of variables indexed by std::string of the variable name. That way scripts can check to see if a given class variable exists in the map and make logic flow decisions that way. yada yada.
The real problem, of course, is that the current design violates object encapsulation. Each class should be in charge of updating its own data. The reason you are having such a hard time is that you have n scripts and m objects and each script updates the data of all m types of objects. That's le supar bad.
Honestly, it's your job as an engineer to point out deficiencies in design. If you see something horribly wrong and don't point it out, it's your fault when it fails. If your lead is hostile to criticism of his design, find another job.
Couple better architectures off the top of my head would be:
1) all objects share a common virtual interface (declared in the base class). Scripts may access objects only via that interface. A properly written script would never care about how functions in the interface are implemented.
2) each script is tied to a specific level of the object hierarchy. In this system the script has a pointer to the specific class for which it was implemented. (this is kinda-sorta how unreal script works; except in unreal script the object is actually defined on the script side of things)
But, basically, what you have is just an awful implementation of a scripting system. There are plenty of great scripting systems already developed whose architectures enforce good design on your side: lua and angelscript, for instance.
-me
How can I use a char* value in the name of a variable?
So, if I understand this correctly, let's say you have a triangle and a box, and both call script "ObjectScript", which would be like:
Right? The answer is pretty obvious. Break the above script into 3 scripts,placing the common code into "ObjectScript":
Have the triangle call the TriangleScript, and the box calling BoxScript. I don't see any reason for all the code to be in 1 script and switching based on argument type, that's pretty stupid.
void ObjectScript(Object* obj){ obj->DoSomeStuff(); if (obj->type==TYPE_TRIANGLE) (Triangle*)obj->DoSomeTriangleStuff(); if (obj->type==TYPE_BOX) (Box*)obj->DoSomeBoxStuff();}
Right? The answer is pretty obvious. Break the above script into 3 scripts,placing the common code into "ObjectScript":
void ObjectScript(Object* obj){ obj->DoSomeStuff();}void TriangleScript(Triangle* triangle){ ObjectScript(triangle); triangle->DoSomeTriangleStuff();}void BoxScript(Box* box){ ObjectScript(box); box->DoSomeBoxStuff();}
Have the triangle call the TriangleScript, and the box calling BoxScript. I don't see any reason for all the code to be in 1 script and switching based on argument type, that's pretty stupid.
Thank you guys for all the help. It does definately seem as if there is no solution with the current setup outside of having seperated scripts for different types. I will have to make this clear to my lead/boss and maybe we can rework some structure to make it more efficient, logical, and overall better as far as code practice is concerned. I am glad everyone pretty much agrees that the setup is just plain stupid, as it has been a concern of mine and another programmers for a while that we have brought up atleast once or twice. Again, thanks.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement