• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
thePyro_13

Wrapping my head around AngelScript

7 posts in this topic

I'm been playing with AngelScript for around a week or so, and having some trouble wrapping my head around how it all fits together. I'm hoping someone here can walk me through what I need to do to achieve what I want.

Basically I just want the entities in my project to be controlled by a script class(one class per entity type). The entities are described by xml(lists the script file, and image files used by the entity).

I think I need a single Script Engine for my entire app. Then do I need to build a module for each entity type? The entities are only different on the scripting side, they all use the same generic class on the C++ side.

I've been trying to work this all out from the Game sample included in the sdk, but some of it leaves me confused. I think it's supposed to be one module per entity, yet the example registers its objects to the engine rather than the module. Do I just register all of my classes(the ones I want scripts to be able to use) to the engine for all scripts to access?

Where is IController coming from? I couldn't find it in any of the script files in the game sample project or in the C++ app. Is it a generic part of AngelScript?

I suspect I'll have a lot more questions as I learn more about this library, sorry in advance if all my questions get annoying. :P
0

Share this post


Link to post
Share on other sites
The game sample shows how to integrate the script engine similarly to how you want.

Let me try to clarify some of the doubts you have:

- You'll use a single script engine. It is possible to use multiple engines, but there are only disadvantages with that. (At least I can't think of any advantages at this moment)
- The application must register all functions and types that the scripts should be able to access in the application. If you wish to provide different functions and/or types to different script modules, for example if you have scripts controlling the GUI too. Then you can use access masks to control which module should be able to access which function.
- You'll have one module for each entity type, i.e. all zombie type entities will share a single module, and the player type will use another module, etc. The script code and global variables in the module will be shared between the entities (could be useful for collective behaviours).
- Each entity should have it's on script class which is instantiated from the entity type's module. The script class holds the class members with the information that only that specific entity has access to.
- The IController interface is registered by the application with RegisterInterface("IController"); The interface could be used to force the script class to implement specific methods, but in the game sample it is only used to facilitate identifying the script class that is supposed to control the entity. You don't have to use this if you don't want. Your XML file with the entity configuration could for example provide the name of the class directly instead.

I hope this clears up some of your doubts.

Regards,
Andreas
1

Share this post


Link to post
Share on other sites
Thanks for your reply. That's helped me heaps.

I'll reply here again if I have any trouble.
0

Share this post


Link to post
Share on other sites
Ok I've been building off the game sample, and have made good headway.

Currently both the level and the entities run from scripts. I've been trying to work out a way to expose a function to the level script which returns a script object handle rather than a handle to a c++ object.

Like this(TestArea.as):
[CODE]
#include "Entity.as" //defines the Entity angelscript class.
class TestArea
{
TestArea(Area @obj)
{
// Keep the owner for later reference
@self = obj;
@skeleton = self.CreateEntity("entites/skeleton/skeleton.xml", 5, 10); //loads the entity data from the xml and creates it.
}

Area @self;
Entity @skeleton;
}
[/CODE]

Where 'CreateEntity' creates a scripted entity and places it in the entity manager associated with this TestArea class. But I'd also like to to return the script object associated with the C++ entity so that I can define additional functions and send data without having to go back through C++ land.

All I have in the C++ entity is it's asIObjectType and asIScriptObject. But I'm not sure how to get the script object in a format that I can pass back to my script.
Basically I want the Entity angelscript object, not the entity C++ object.

Is this possible? Any help will be greatly appreciated! :D
0

Share this post


Link to post
Share on other sites
What you need is [url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_script_shared.html"]shared classes[/url]. Shared classes compiled in two different modules will share their code and typeids, which makes it possible to pass a pointer to that shared class from one module to the other. The drawback with shared classes is that they cannot access any non-shared entities, such as global variables or functions that have not been declared as shared too.

I assume your Entity class is the base class that all script controllers inherits from. Am I right? The Entity should then be declared as shared. The script controllers can still inherit from it without themselves being shared.

The CreateEntity() method should create the script controller instance, and then return the asIScriptObject pointer. As the controller inherits from the Entity class the level script will then be able to use is such.

Regards,
Andreas
1

Share this post


Link to post
Share on other sites
That's right, they all inherit from Entity(except the level scripts).

I've declared it as shared, but I'm having trouble defining the interface.
[CODE]
r = ScriptEngine->RegisterObjectMethod("Area", "asIScriptObject@ CreateEntity(std::string source, int posx, int posy)", asMETHOD(Area, CreateEntity), asCALL_THISCALL); assert( r >= 0 );
[/CODE]

This line throws an assert. Do I have to register to Entity type to the Script engine? And do I define the function above as returning asIScriptObject@ or Entity@(The C++ function is now returning asIScriptObject*)? Edited by thePyro_13
0

Share this post


Link to post
Share on other sites
I'm sorry. I misunderstood your problem.

When registering the application interface, the engine still doesn't know of the Entity script class, so you can't register any functions that take or return that class. There are two ways of getting around this problem.

1. First register an interface from the application, e.g. RegisterInterface("IEntity"). The CreateEntity method can then be registered to return a handle to that interface, i.e. "RegisterObjectMethod("Area", "IEntity @CreateEntity(...)", ...). The Entity script class obviously needs implement the inteface for this to work. As the script that calls CreateEntity will receive an IEntity it needs to cast the handle to the Entity class before accessing its members, unless you registers methods directly with the interface.

2. Use the generic handle add-on, i.e. [url="http://www.angelcode.com/angelscript/sdk/docs/manual/doc_addon_handle.html"]CScriptHandle[/url], to return a handle that the script can cast to Entity as needed. In this case the CreateEntity() method will be registered to return the generic handle, i.e. "ref @CreateEntity(...)", which the calling script can cast to an Entity class. The implementation of the CreateEntity() method needs to be modified to return a CScriptHandle object by value.

[code]
CScriptHandle Area::CreateEntity(...)
{
...

// Create the Entity instance
int typeId = module->GetTypeIdByDecl("Entity");
asIScriptObject *obj = reinterpret_cast<asIScriptObject*>(engine->CreateScriptObject(typeId));

// Prepare the generic handle object for returning the Entity instance
CScriptHandle handle;
handle.opAssign(obj, typeId);

// The generic handle will hold on to its own reference, so we need to release ours
obj->Release();

// Return the generic handle object by value (even though the method is registered as 'ref @')
return handle;
}
[/code]



I had an idea for an improvement in the library because of this problem you've faced. The application could register the name of the shared class as part of the configuration. This would allow it to register objects taking or returning the type. When the script is then compiled it will fill in the members and properties of the type. This would greatly simplify the solution for your problem. I'm not sure I'll be able to implement this for version 2.24.0, but I'll add this to my to-do list for a later release.
0

Share this post


Link to post
Share on other sites
Thanks for your help. I've got it working now with the scripthandle add-on.

Thanks for taking your time to help me. The angelscript library is really cool. :D
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0