Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 03 Jan 2011
Offline Last Active Yesterday, 06:48 AM

Topics I've Started

Forward declarations

Yesterday, 06:17 AM

Is there any chance (or did I miss it somehow?) that angel script could support forward declaration?


Like defining classes in a different place from the declaration:


class A


     void helloWorld();



void A::helloWorld()





Is something like this going to happen?

How to make classes and objects from another module accessible?

02 July 2014 - 06:08 PM



I know I asked a similar question before but I still have one doubt.


So, my game has N states (individual screens like pause, menu, game etc) and each one lives in its own module and communicates with other states exclusively using a central queue, so all information gets to the destination indirectly.


But now, I also added behaviors to the engine, where each behavior is a script that controls an entity's behavior. For example, one behavior script might give an artificial intelligence to the character, another just make it follow a path etc.


For now, each behavior is a custom class, such as class MyBehavior : Behavior {}, and is also living in its own module and loaded from its own script file, which works fine to deal with its attached entity and give it behavior. However, now I need that my game state script is able to retrieve data from any of this behaviors currently instanced, like:


// this is the game state script

behaviorClass@ behaviorObject = cast<behaviorClass@>( GetBehavior("entityName", "behaviorClass") );

behaviorObject.x = ; // set or get variables declared in the external file of the given behavior


I'd like to add that the behaviors are hot reloadable, so I basically shut them down and re create them once the script source has changed, in order to have the most recent version running in the game without re-running the process. Is there a way to do something similar to this with AngelScript? I am not sure if the game state script module could either dynamically bind to these external behavior classes or just remove and recompile the code sections respective to the behavior scripts so they are in scope, while operating on instanced objects of behavior classes created in the other module.




As a second question, just wanted to ask if there is a way to associate member variables with the pure angelscript interfaces. I basically want that when I implement a new behavior, as it inherits the interface Behavior, it would automatically inherit a member Entity@ attachedEntity, so even if my custom behavior class has no members it still knows about which entity that instance is attached to. I am asking as I didn't see any C++ api function to do this, interfaces seemed to only be able to define the virtual methods and actual interface name, 


The solution I thought about was to define myself a base class that is actually a angelscript class rather than an interface, this way I could do anything to it and pre-implement functions etc, is this the way to go?


Is there any chance you can implement in the future some kind of explicit and/or implicit conversion mechanism when calling a function? Like MyBehavior@ a = getBehavior<MyBehavior>() or have it return instead an abstract handle to the base type that can be automatically casted to the expected type of 'a'? I am talking about doing these with only script classes here

Inter-module class access

24 May 2014 - 04:45 AM



I am currently trying to solve an issue and I'd like some direction on the best way to handle it.


In essence, my game has a few states (intro, loading, menu, game, pause, etc), each state is a unique class defined in a unique file, and they all inherit from a common interface GameState.


Right now, I am compiling each class into its own module, which creates the problem that I can't access classes from other modules and I need to do things like that, for example, the loading script would get the handle to the game script object, and would change some values in that state object for game initialization. 


How should I handle this? Move all classes to a single module so they can access each other mutually? Should I use a messaging system instead? Is there any other recommended way?


Also, in case of maintaining a single module for all my classes, besides avoiding name collisions, should I have any other concerns? Is there a problem if I add later other classes into this module, whenever there is the need?



Is there a bug with function callbacks?

10 April 2014 - 05:34 AM



My use case is really simple, I have a button object, which holds a asIScriptFunction pointer with its callback in a script, called when the button is clicked. If the button is clicked and the function is NULL, it does nothing, if it is a valid function, it calls it so the script can react to the event.


I did everything like the manual but I get a compilation error. First, I registered my funcdef:


asx.get()->RegisterFuncdef("void UICallbackFunction()");


Then, I register my UI connect function to bind buttons to script functions: 


asx.get()->RegisterObjectMethod("UICanvas", "void connect(const string& in, UICallbackFunction @cb)", asMETHOD(UICanvasScriptInterface, connectClick), asCALL_THISCALL);


The connectClick() method has the following signature: void connectClick(const String& name, asIScriptFunction* callback)


And, in the script, I am doing this: ui.connect("myButton", onMyButtonClicked); , where onMyButtonClicked is a void onMyButtonClicked() function. It all seems pretty much like the manual, except im registering the callback through a method instead of a global function.. right?


What is wrong? My compilation error is as follows:

ERR: No matching signatures to 'UICanvas::connect(const string, onMyButtonClicked)'

INFO: Candidates are:

INFO: void UICanvas::connect(const string&in, UICallbackFunction@)


The funcdef indeed has the same signature as the target callback function..


EDIT: I actually tried to make it all like the manual: http://www.angelcode.com/angelscript/sdk/docs/manual/doc_callbacks.html . Same problem :(


My regards,


Changing the content of global variables from C++

05 April 2014 - 03:26 PM



I don't know if I am missing something in the documentation, but I don't seem to find a way to alter a global variable in a script.


Here's my use case:


I have a behavior script attached to an entity. This behavior script has a Update() function called every frame, and has the following global variable: Entity@ entity = null;


Since this behavior is attached to multiple entities, entity must point to the appropriate object every time I call Update().


But I can't seem to be able to make entity reference a valid object from C++, before calling the script function Update(). Any tips on how to do it?

The closest I've been was getting the global var address, which indeed points to null, as initialized. But I can't seem to make it reference the appropriate entity before calling Update()..