using multiple scripts with the same function name
Hi,
I''ve got a question: I''ve got a situation when I need that every entity in my game has got a script file which describes its basic AI behaviours and physics. It''s quite natural thing that every script has got the same main function name which starts executing ie. AI, let''s call it "MainAI". So I need to compile my scripts and there''s a problem because I''m not allowed to declare more than one function with the same name. What would be the solution for the case?? I thought about using separate asIScriptEngine for every script but then I''d need to add global function/object to the freshly created asIScriptEngine any time I want to create any script. How much memory those declarations need inside AngelCode?? Can I use this method safe?? Other thing which came to my mind is to use a script without "main" function and then before passing the code to AngelCode add the "main" function at the top of the script, but what would happen if I have declared functions in the code?? Can I declare functions within other functions??
Thanks,
Ltq
From what I understand namespaces are in the near future, meaning you could multiple scripts with the same name if they were declared in different namespaces.
One workaround at the moment would be to to append MainAI onto the end of whatever the AI is for, e.g. if it was for a character called Grunt you would have a GruntMainAI function. Thats just a strcat in code. I''m not too fond of that solution, but it works.
One workaround at the moment would be to to append MainAI onto the end of whatever the AI is for, e.g. if it was for a character called Grunt you would have a GruntMainAI function. Thats just a strcat in code. I''m not too fond of that solution, but it works.
Desdemona has the right idea. Currently the recommended solution is to prefix the functions with the name of the object. Sort of a poor man''s namespaces.
You can create one script engine for each object type, and it shouldn''t affect your performance. The main disadvantage is that the two script engines cannot share global variables or common functions. Both engines must also be configured with the Register functions. I''m not sure about how much memory the registered functions require, but a guesstimate is about 50-100 bytes each.
Functions cannot be nested.
Version 1.8.0 will have support for modules. Each module will have it''s own namespace, which means that you will be able to reuse the function names. Each module can also be independently compiled, which means that you can add/remove modules from the engine without affecting the others.
It is my hopes that version 1.8.0 will be released next month. But this depends heavily upon how much time I will have to work on AngelScript. I will release one other version before that, v1.7.1 with support for function overloading with script functions and ExecuteStep(asEXEC_STEP_OVER). That one should be finished within a week, I hope.
As you might guess, the release dates are very vague, but hopefully I will be able to keep them. I''ve been known to finish a release before the estimated time as well.
__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game
You can create one script engine for each object type, and it shouldn''t affect your performance. The main disadvantage is that the two script engines cannot share global variables or common functions. Both engines must also be configured with the Register functions. I''m not sure about how much memory the registered functions require, but a guesstimate is about 50-100 bytes each.
Functions cannot be nested.
Version 1.8.0 will have support for modules. Each module will have it''s own namespace, which means that you will be able to reuse the function names. Each module can also be independently compiled, which means that you can add/remove modules from the engine without affecting the others.
It is my hopes that version 1.8.0 will be released next month. But this depends heavily upon how much time I will have to work on AngelScript. I will release one other version before that, v1.7.1 with support for function overloading with script functions and ExecuteStep(asEXEC_STEP_OVER). That one should be finished within a week, I hope.
As you might guess, the release dates are very vague, but hopefully I will be able to keep them. I''ve been known to finish a release before the estimated time as well.
__________________________________________________________
www.AngelCode.com - game development and more...
AngelScript - free scripting library - Tower - free puzzle game
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement