🎉 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!

Unconstructable objects

Started by
2 comments, last by WitchLord 19 years, 2 months ago
Is it possible to register an objectin Angel as "unconstructable"? What I mean is, lets say I have a function:

OnHit(Player@ player)
{
   DoSomething();
}
Now, I want to be able to pass in an object handle of type 'Player', but I don't want the script user to be able to actually instanciate a new object of type player. I am assuming that declaring a non-handle object is the same as instanciating it, like so:

Player somePlayer;
I am making this assumption because no 'new' keyword exists. Basically, is there any way to stop the script user from doing this? I don't want script users to be arbitrarily creating object instances all over the place. I will give them the data they need inside the script execution context. EDIT: Let me preface this quickly with why this is important to me. I am evaluating using Angel as the backbone of a multi-user text game engine I am writing (oh yes, another MUD engine). Obviously I must be very strict in my control of the script environment. I can't let content builders go crazy and bring down the server, by accident or otherwise.
Matt Holmes[ aka Calefaction ]Wildfire Games - General Programmerhttp://www.wildfiregames.com
Advertisement
Yes, this is possible. When you register the object type you should set the size of the object to 0, that will tell that compiler that this type cannot be instanciated as a variable (local or global). By then registering the behaviours ADDREF and RELEASE the object can be manipulated through handles.

engine->RegisterObjectType("Player", 0, 0);
engine->RegisterObjectBehaviour("Player", asBEHAVE_ADDREF, "void f()", asMETHOD(Player,AddRef), asCALL_THISCALL);
engine->RegisterObjectBehaviour("Player", asBEHAVE_RELEASE, "void f()", asMETHOD(Player,Release), asCALL_THISCALL);

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

Thanks for the quick reply :)

One question, would the coder then be able to do player.AddRef(); and player.Release()? Or are those just internally used behaviors?
Matt Holmes[ aka Calefaction ]Wildfire Games - General Programmerhttp://www.wildfiregames.com
Those behaviours cannot be called explicitly (unless you also register them as normal object methods). There are called by the engine when a handle assignment is made, or a handle goes out of scope.

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