Taking different parameter types
Alright, I'll make these changes.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
It turns out that the way I have things set up, it'll be much easier for my game to use ExecuteString() to call functions, i.e. like this:
Is there any difference between doing that and using Prepare(), SetArg(), and Execute()? I've run a few tests and everything seems to work the same... however, I'd like to be sure about it before I start developing a lot based on it.
ExecuteString("Say_To_User(1, \"Hello!\")");
Is there any difference between doing that and using Prepare(), SetArg(), and Execute()? I've run a few tests and everything seems to work the same... however, I'd like to be sure about it before I start developing a lot based on it.
If you can represent all your arguments as strings, then the only difference is that ExecuteString is slower, in that it needs to compile the string and then execute it.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
Hmm... sounds like that'll be fine, because if I didn't use ExecuteString(), I'd have to write some function of my own that would end up doing the same, and it'd probably be slower.
I figure I'll have all my script functions in one file, then use ExecuteString() to call them whenever I need to. Thank God (or rather, WitchLord) for that function! It's making things a lot easier.
I figure I'll have all my script functions in one file, then use ExecuteString() to call them whenever I need to. Thank God (or rather, WitchLord) for that function! It's making things a lot easier.
derefed, I most likely have missed something, so please forgive me for asking, but why?!?
This way is slower, and IMHO, limits what you can do with the scripting engine.
As WitchLord indicated, you have to be able to represent all your parameters as strings. If this is what you are always going to be doing, you can easily write a wrapper for this, and not limit yourself to using a slow function call.
If, on the other hand, you are having to serialize your objects into strings so you can easily call your functions... O_o. My 2 cents is that you should really think hard about this.
This way is slower, and IMHO, limits what you can do with the scripting engine.
As WitchLord indicated, you have to be able to represent all your parameters as strings. If this is what you are always going to be doing, you can easily write a wrapper for this, and not limit yourself to using a slow function call.
If, on the other hand, you are having to serialize your objects into strings so you can easily call your functions... O_o. My 2 cents is that you should really think hard about this.
I want to do it this way because all of my function calls aren't being made from my C++ code, but rather from an XML file that stores all data for the game.
The game is text-based, and resembles a MUD. A room, for instance, is represented like this:
I would then have an AS file where the Set_Var function was defined. In this case, entering this room causes a variable "room1_visited" to be set to "true". Other uses would be to have an NPC start a conversation with you upon entering the room, or perhaps something as complex as having an item appear when you say a certain word to someone, and having several hostile NPCs spawn.
The reason I'm even using a scripting language at all is so I can program behaviors for rooms, NPCs, items, etc. without tampering with the source code for the game engine itself. I want people to be able to write their own worlds by writing an XML file to store all the data and an AS file to script all the behaviors/actions of entities in the game.
Now, the only way that I can see to do this without ExecuteString() is to parse the value of the "call" attribute to extract the variables/values, convert them into their proper C++ types, and send them into AS the way you propose... this seems like it would take a lot of work and would no doubt be slow. Additionally, I could also do something like:
However, this isn't quite as streamlined as the above code; I want it to be akin to using javascript with HTML.<br><br>If there's a better way to do this, I'm all ears.
The game is text-based, and resembles a MUD. A room, for instance, is represented like this:
<room id="1"> <name>Grassy field</name> <description>You find yourself in a vast field of tall grass.</description> <exits> <exit hotkey="n" description="North" roomid="2" /> </exits> <events> <onEnter call="Set_Var('room1_visited', 'true')" /> </events></room>
I would then have an AS file where the Set_Var function was defined. In this case, entering this room causes a variable "room1_visited" to be set to "true". Other uses would be to have an NPC start a conversation with you upon entering the room, or perhaps something as complex as having an item appear when you say a certain word to someone, and having several hostile NPCs spawn.
The reason I'm even using a scripting language at all is so I can program behaviors for rooms, NPCs, items, etc. without tampering with the source code for the game engine itself. I want people to be able to write their own worlds by writing an XML file to store all the data and an AS file to script all the behaviors/actions of entities in the game.
Now, the only way that I can see to do this without ExecuteString() is to parse the value of the "call" attribute to extract the variables/values, convert them into their proper C++ types, and send them into AS the way you propose... this seems like it would take a lot of work and would no doubt be slow. Additionally, I could also do something like:
<onEvent call="Set_Var"> <param type="string" value="room1_visited" /> <param type="bool" value="true" /></onEvent>
However, this isn't quite as streamlined as the above code; I want it to be akin to using javascript with HTML.<br><br>If there's a better way to do this, I'm all ears.
I think you'll be alright with using ExecuteString for what you want to do, it will definitely be the easiest way to implement it. Being a text based game I hardly think you'll be having problems with performance either.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
derefed, thank you. That does seem a reasonable approach. Again, I do worry that you can't pass objects around, but this doesn't seem to be an issue.
I've been doing a bunch of reading, and ran over this. The end implementation would be very similar to what SiCrane linked too, but it would not have as much redundant code. What i mean is it would not have this:
And one could easily add more parameters w/o a problem.
You then get the type safety, but the flexibility of an unknown amount of template parameters.
I've been doing a bunch of reading, and ran over this. The end implementation would be very similar to what SiCrane linked too, but it would not have as much redundant code. What i mean is it would not have this:
template <typename OP> inline void ExecuteSetArg(asIScriptContext* ctx, int arg, OP op){ /* shouldn't reach here */ }template <> inline void ExecuteSetArg(asIScriptContext* ctx, int arg, DummyOperand op){ /* do nothing */ }template <> inline void ExecuteSetArg(asIScriptContext* ctx, int arg, asQWORD op){ ctx->SetArgQWord(arg, op); }template <> inline void ExecuteSetArg(asIScriptContext* ctx, int arg, asDWORD op){ ctx->SetArgDWord(arg, op); }template <> inline void ExecuteSetArg(asIScriptContext* ctx, int arg, double op){ ctx->SetArgDouble(arg, op); }template <> inline void ExecuteSetArg(asIScriptContext* ctx, int arg, float op){ ctx->SetArgFloat(arg, op); }template <> inline void ExecuteSetArg(asIScriptContext* ctx, int arg, void* op){ ctx->SetArgObject(arg, op); }
And one could easily add more parameters w/o a problem.
You then get the type safety, but the flexibility of an unknown amount of template parameters.
Let's say, for the sake of argument, that performance *was* an issue, but I had the same setup in terms of using an XML file for data and calling functions from there. (I plan to do a graphical game in the future that would no doubt store data / scripts in the same manner.) What approach would you recommend? Would this:
sort of thing be the way to go? From that info, my XML parser would get the info on what type the variables should be and could call the right SetArg() functions to be sent into the interpreter.
<onEnter call="Some_Function"> <param type="int" value="47" /> <param type="string" value="hello world!" /></onEnter>
sort of thing be the way to go? From that info, my XML parser would get the info on what type the variables should be and could call the right SetArg() functions to be sent into the interpreter.
Without seeing everything working together, your way seems reasonable. A few questions/comments though:
- You need a way to return a value. Yet that can easily be addressed.
- You cannot pass objects to your function
It's a nice simple way of doing things, but I just feel limited by it...am not 100% sure why though...
- You need a way to return a value. Yet that can easily be addressed.
- You cannot pass objects to your function
It's a nice simple way of doing things, but I just feel limited by it...am not 100% sure why though...
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement