Advertisement

A few noob questions

Started by September 03, 2011 03:42 PM
2 comments, last by WitchLord 13 years, 5 months ago
Hi everyone,

I'm curently developing an small 3d game engine. I have expercience with unreal development kit. After a long time searching for the most suitable script for my engine I decide to use Angel Script.
First of all sorry for my english, it is not very good...
Second thank's for this great script! Is amazing!!!!

Okey, now my questions:

---------------------------------------------------------------------------------------------

1.- Has Angel script support for class type variables? Something like:
class<FooBase> FooClass = class'Foo';
new FooClas(....);
If it not support it, it's easy to implement?

---------------------------------------------------------------------------------------------

2.- Can angel script class inherit from c++ exposed class, and how?

---------------------------------------------------------------------------------------------

3.- It will be very difficult to implement states? Like: (this question is not very important, but it is a nice feature)
class Foo
{
void doSomething() {...}

state Running
{
void doSomething() {... }
}
};
...
fooVar.goToState('Running');
fooVar.doSomething(); // <- Here exectue Foo::Running::doSomething function
...

---------------------------------------------------------------------------------------------

4.- I see on the website that there exist an extension with metadata, but it have to be declared outside the class. Its possible or easy to implement something like this?

class Foo
{
[save] int i;
[editor] int live;
...
};

---------------------------------------------------------------------------------------------

5.- Angel script handle well circular references?

---------------------------------------------------------------------------------------------

Sorry another time for my english, I hope it will not be very difficult to understand this questions.

Thanks a lot.
Hi junkyska,

I'm happy you like AngelScript and that you've selected it for your project.




1. I'm not sure I understood your question, but I'll try to answer they way I understood it:

Yes. AngelScript supports template types. The array add-on is a good example, which will allow the script to declare arrays as: array<int>, array<mytype@>, etc.



2. No, AngelScript classes cannot inherit from C++ registered classes. However, it is possible to emulate the inheritance: http://www.gamedev.net/community/forums/topic.asp?topic_id=535837



3. States like those in Unreal script is not supported yet. Though it should be quite possible to emulate by using prefixes for the class methods, like:

class Foo
{
// Default state
void doSomething() {...}

// State Running
void Running_doSomething() {... }
};



4. HardGuy from Frictional Games have recently contributed an improvement to the metadata implementation that supports exactly what you're looking for. http://www.gamedev.net/topic/606364-custom-keyword-and-object-type-flag-solved-code-attached/page__gopid__4851912#entry4851912

It will be available in the next release.




5. Yes. AngelScript is fully capable of resolving circular references. It has an incremental garbage collector that will detect and destroy these scenarios.




Regards,

Andreas

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement
Thanks for the answer!! Now I know better how I can implement my code.

I have trubles with the frist question.
I didn't know that AngelScript support templates, this is a good feature. But what I'm asking is that in Unreal Script there are a variable type that holds a class type not a class object. Imagine that you have this classes:

class FooBase
{

};

class Foo : public FooBase
{

};

class InitFooBase
{
class<FooBase> fooClass;
FooBase fooVar;

InitFooBase()
{
fooClass = class'FooBase';
}

void initFoo()
{
fooVar = new fooClass();
}

};

class InitFoo : public InitFooBase
{

InitFooBase()
{
fooClass = class'Foo';
}

};

So just changing the fooClass variable the InitFooBase creates the apropiates one. Sorry but it's difficult to me to explain.
What I'm asking is the 'name' variable type in Unreal Script.
His definition is: "Name: The name of an item in Unreal (such as the name of a function, state, class, etc). Names are stored as an index into the global name table. Names correspond to simple strings of up to 64 characters. Names are not like strings in that they are immutable once created".

I think it will not be possible because in Unreal Script you have only one default constructor without parameters (ugly feature) but in Angel Script like c++ you have custom constructors, so the sentence new fooClass() it might take differents parameters.

It's not an important feature but just I want to know how I have to implement my script logic.

When it will be available the next relase (for the metadata info)?

Sorry if I'm comparing to much to Unreal Script, it's just that I work a lot with it and I love some features.

Keep the good work, because it's a very nice library.

Thanks.
Unfortunately I do not have much knowledge in UnrealScript. However, from the example you showed me it seems the feature you're looking for is if there is a way to create classes based on their name.

It can be implemented in many ways. One way I can think of is like this:


// C++

// Use the script handle add-on to support generic handles
#include "add_on/scripthandle/scripthandle.h"

// This function is registered as 'ref@ CreateObject(const string &in)'
CScriptHandle CreateObject(const string &name)
{
asIScriptContext *ctx = asGetActiveContext();
asIScriptEngine *engine = ctx->GetEngine();

// Determine the module that is currently in use so we can match the name to a type in that module
asIScriptModule *mod = engine->GetModule(ctx->GetFunction()->GetModuleName(), asGM_ONLY_IF_EXISTS);

// Create an instance of the desired type
int typeId = mod->GetObjectTypeIdByDecl(name.c_str());
asIScriptObject *obj = reinterpret_cast<asIScriptObject*>(engine->CreateScriptObject(typeId));

// Return the handle to the object in the generic handle type
return CScriptHandle(obj, typeId);
}


From the script this would be used like this:


// AngelScript
class MyType {}

void main()
{
// Create an instance of the class MyType, based on it's name
MyType @type = cast<MyType>(CreateObject('MyType'));
}




Please don't hesitate to ask for features from other script languages. This is exactly what I need to enhance AngelScript even further.




You can use HardGuy's code immediately if you wish, it's available in the forum thread I linked to above. However, the next release for AngelScript is likely to be ready in a few weeks. I normally manage to release a new version every 1 or 2 months.






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