Write plugin in AScript
I want to let the users write their new weapons and put them into my game.I think it will be nice if they can write a script file which contain the code of weapon and put it in the "weapon_plugin" folder for example,and then the engine will automately loop every ".as" file in the folder and load them.
Here is my problem:
in c++ I can do this
for each .dll file in folder
{
LoadLibrary(filename)
Func=GetProcAddress(...,"LoadWeapon");
Func();
}
But I don't know how to do the same stuff in AngleScript.
for every weaponxxx.as file should has the ability to use all the game core script functions and classes , So I think it should be AddScriptSection to the game core module.But if there are multiple weapon plugins ,they can't use the same entry function name as "LoadWeapon",So how can the game engine load the weapons?
Ya use boost for something to iterate every file in the folder, and I believe boost can give u the file extension nicely too (but u can do this how ever u want of course) and then u would just load/compile each .as script as you encountered it I would think.
Then you could refere to it by it's module name (usually file name in my case, but could work out some system where you assigned some sensible string, like a weapon name, instead)
Then you could refere to it by it's module name (usually file name in my case, but could work out some system where you assigned some sensible string, like a weapon name, instead)
If I load every plugin as seperate module,How can this module call the core module fuctions and class?
Is there a method to use the other module's class?
Is there a method to use the other module's class?
You can use the import functionality to bind functions from other modules.
Manual: Imports
Manual: asIScriptModule::BindAllImportedFunctions
There is not so much documentation on this in the manual because once I have implemented function pointers I plan on changing the way this works.
While I do not recommend the test_feature for learning purposes, you can take a look at the test_import.cpp and test_import2.cpp for ideas.
Manual: Imports
Manual: asIScriptModule::BindAllImportedFunctions
There is not so much documentation on this in the manual because once I have implemented function pointers I plan on changing the way this works.
While I do not recommend the test_feature for learning purposes, you can take a look at the test_import.cpp and test_import2.cpp for ideas.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
use the import functionality ,I can only call the plugin module functions from core module,But in plugin module I can't use a class which is declared in core module.
So should I include every core module .as files in plugin module?
So should I include every core module .as files in plugin module?
The plugin module can also import the functions that it will use from the core module.
You can't just include the core scripts in the plugins as that will duplicate the bytecode, and class definitions. You can however declare interfaces for your classes in the core module, and then provide imported functions for retrieving object handles to these interfaces, thus allowing the plugins to access the classes declared by the core module.
You can't just include the core scripts in the plugins as that will duplicate the bytecode, and class definitions. You can however declare interfaces for your classes in the core module, and then provide imported functions for retrieving object handles to these interfaces, thus allowing the plugins to access the classes declared by the core module.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game
And In the plugin,Can I write a class derive from core module class?
for example in core module:
class WeaponBase
{
...
};
in plugin module:
class Shotgun:WeaponBase
{
...
}
Can I do this?
for example in core module:
class WeaponBase
{
...
};
in plugin module:
class Shotgun:WeaponBase
{
...
}
Can I do this?
No, if the base class is in another module then you can't derive from it. The base class isn't visible in this case.
However, as I said before, you can have an interface. Handles to WeaponIntf can then be exchanged between the core module and the plugin module.
If you wan't to provide a default implementation for the weapon you can declare that base class in the plugin module, but the core module won't know about it.
However, as I said before, you can have an interface. Handles to WeaponIntf can then be exchanged between the core module and the plugin module.
If you wan't to provide a default implementation for the weapon you can declare that base class in the plugin module, but the core module won't know about it.
// ---------------------------------// Same interface declared in core module and plugin module.// Usually you'll want to include this from a common script// file, to make sure it is really the same declaration.interface WeaponIntf{...}// ---------------------------------// in plugin module// Default implementation, visible only to the plugin.// This can be be included from a common script file, so // it doesn't have to be rewritten for each plugin.class WeaponBase : WeaponIntf{...}// The custom weapon type, derives from the default implementation// which in turn implements the WeaponIntf interface that the// core module can interact withclass Shotgun : WeaponBase{...}
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