🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

AngelScript 2.10.0 released

Started by
25 comments, last by WitchLord 16 years, 7 months ago
Well, if you registered multiple objects of the same type as global properties, and want to choose between them in the scripts. Ex: Two different factory objects, say one for dumb enemies and one for smart enemies, and you wanted the script to use a different factory depending on the difficulty level.
Advertisement
Quote: Original post by WitchLord
Why would you want that? If it is already available as a global property, why pass it around as a parameter?


yes, SiCrane is right.
And lets take a look from an another point of view - I have a function, foo(const my_class ∈), in the module "global_functions". I build this module in the begining of my application. Later in my code I register several my_class global properties, a, b, c, and I simply want to call foo(a), foo(b), foo(c).
my_class is very complex, it could not be constructed in a script, my_class objects are created by an application's core as a response to external events.

Currently I'm using unsafe references for that, works nice.
Hmm, interesting. I understand what you want now and it makes perfect sense. But why not use object handles?

If you register the type with asOBJ_REF but don't register the asBEHAVE_FACTORY, the script won't be able to instanciate objects, but can receive and pass around object handles/references of the objects.

If desired, I could potentially add a flag that will let you tell AngelScript to not allow declaration of variables with object handles of the type. That would allow AngelScript to use object handles to guarantee the lifetime of the objects, but avoid having the scripts store unwanted handles to objects that may live longer than the script itself.

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

Quote: Original post by WitchLord
Hmm, interesting. I understand what you want now and it makes perfect sense. But why not use object handles?


I'm not familiar with AS object handles. If I understood right, I need some proxy class for proper reference counting since I could not add asBEHAVE_ADDREF, asBEHAVE_RELEASE etc. behaviours directly to my complex classes. And that proxy classes are another headache for me :)

Also, I'm unsure of object handles abilities. Please take a look at my code

C++ code:
// signal_t is a core class from my slot/signal library, I don't want// this class to be constructed in a scriptr = engine->RegisterObjectType("signal_t", 0, asOBJ_REF | asOBJ_NOHANDLE); // this is actually a call to ExecuteStringr = engine->RegisterObjectMethod("signal_t", "void eval(const string_t ∈)", asFUNCTION(signal_t_eval), asCALL_GENERIC); //// another "big" class representing a whole message box on the screen//r = engine->RegisterObjectType("message_box_t", 0, asOBJ_REF | asOBJ_NOHANDLE); // my lovely piece of coder = engine->RegisterObjectProperty("message_box_t", "signal_t signal_hidden", offsetof(message_box_t, signal_hidden)); r = engine->RegisterObjectProperty("message_box_t", "signal_t signal_first_button_clicked", offsetof(message_box_t, signal_first_button_clicked)); r = engine->RegisterObjectProperty("message_box_t", "signal_t signal_second_button_clicked", offsetof(message_box_t, signal_second_button_clicked)); 


AS code
// a function working with signal_tvoid foo(signal_t& signal) {...};...// shows "Quit?" message on a screen + two buttonsmsgbox.show("Quit?", "Yes", "No");// will call ExecuteString("save_settings(); exit_app()") // if the first button was clickedmsgbox.signal_first_button_clicked.eval("save_settings(); exit_app()");...// sometimes I need to pass a reference to the real // signal_t object into AS functionfoo(msgbox.signal_hidden);


Is it possible to code this way using object handles??


Quote:
If you register the type with asOBJ_REF but don't register the asBEHAVE_FACTORY, the script won't be able to instanciate objects, but can receive and pass around object handles/references of the objects.

If desired, I could potentially add a flag that will let you tell AngelScript to not allow declaration of variables with object handles of the type. That would allow AngelScript to use object handles to guarantee the lifetime of the objects, but avoid having the scripts store unwanted handles to objects that may live longer than the script itself.


Looks like that potentially could help to stop using unsafe references, right?

If you don't care about the reference counting, and can guarantee that the objects live longer than the scripts you can just register a couple of dummy functions for the AddRef and Release behaviours. That way you don't need any proxy classes.

The object handles should allow you to do what you want, without the need to use unsafe references.

The ideal would be if you really implemented reference counting for your objects. At least that way you would know if the script holds any references to your objects before releasing or reusing them.

I think I'll see if can implement a flag for disallowing object handle variables for a type, even though handles should be allowed for the script engine's internal use.

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

when will the next version release?

will it support pointer?(the test_pointer sample)

thanks
Version 2.11.0 is coming around the corner. I just have a little more polishing to do.

Pointers won't be supported for a long time yet, there are too many other features to implement first. However, you can quite easily register a 'pointer type' that lets you store and manipulate pointers if you wish. It won't have the nice built-in syntax support as in C++ (and earlier versions of AngelScript) but it will work.

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

This topic is closed to new replies.

Advertisement