Skip to main content
gamedev.net
🔒 Locked

Some basic questions

Started by sonicbhoc Jan 4, 2010 at 4:44 PM 7 replies 2k views
Original Post
sonicbhoc
sonicbhoc
I have a few basic questions about the capabilities of AngelScript (I have 2.18.0 stable by the way). First of all, I am creating C++ objects (content managers) and wish to register some member functions - specifically loading functions - of those objects as global functions in AngelScript. Can I do that? Second of all, a lot of people recommend that the bulk of the game be scripted and the heavy lifting be done by C++. Do you guys recommend that too?
WitchLord
WitchLord
1)

If the class methods are static, then you can register them as global functions directly. If they are not static then you cannot, because AngelScript wouldn't have the object pointer.

However, you can register your content manager as a singleton in AngelScript, then let the script call the methods on that singleton. Example:

  contentMgr.LoadImage('myimage.png');


(In a future version of AngelScript I may make it possible to register a class method as a global function directly.)


2)

If you plan on writing a game where you intend to re-use the engine in other games in the future, then it is definitely recommended that you separate the game logic from the game engine. One way of doing this is by using scripts for the game logic.

It's not the only way though. The game logic can be separated from the rest of the game engine through ordinary C++ modules that interacts with the game engine through clearly defined interfaces.

There is not one answer that fits all. Whether using scripts is better than writing the game logic in C++ (or whatever programming language you use) has to be determined based on your game. For smaller games it may not be worth the extra effort to write the script/application interface, but for larger games it usually is, especially if you plan on having other developers write the game logic for you. By using scripts, a less experienced programmer can easily write the game logic.

Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
sonicbhoc
sonicbhoc
Thanks dude.
So, I'd have to make them static... hmm. Well, the methods I'm trying to register are all from singletons anyway so I don't think it would have much of a difference...

I was trying to avoid registering objects because the documentation on it confused me ^_^;;

Do single-reference types need factory functions too?
WitchLord
WitchLord
No it doesn't. AngelScript will return an error if you try to register a factory for it.

You would normally register a singleton the following way:

// Register the singleton type so that the script can use it, but not create new instances, or store references to itr = engine->RegisterObjectType("singleton", 0, asOBJ_REF | asOBJ_NOHANDLE); assert( r >= 0 );r = engine->RegisterObjectMethod("singleton", "void DoSomething()", asMETHOD(singleton, DoSomething), asCALL_THISCALL); assert( r >= 0 );// Register the singleton's address that the script will use to access itr = engine->RegisterGlobalProperty("singleton single", &single); assert( r >= 0 );


Regards,
Andreas
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
sonicbhoc
sonicbhoc
Thanks, I didn't do the RegisterGlobalProperty step (I didn't see it in there anywhere). I should've realized that I needed that in there, though.

I'm registering all of the different managers I have in my program that will be used.

Another question: from what I read, AngelScript supports concurrently-running scripts. What would be the pros and cons for having different types of scripts (character scripts, level scripts, etc) running concurrently?
WitchLord
WitchLord
Yes, you can have concurrently running scripts. The ContextMgr add-on provides this support for you.

Supporting concurrently running scripts can make it easier for you to write long running scripted sequences, like animations and such.

One disadvantage of using long running concurrent scripts is that it is not yet possible to serialize a script context in AngelScript. So if you do use long running scripts then you will only be able to save the game progress at moments where you have exact knowledge of the state of these scripts, i.e. specific check-points. However, if you only use the long running scripts for non-critical stuff, like GUI animations, etc, then there shouldn't be any problem.

Another disadvantage may be the memory consumption. If you have lots of concurrent scripts you will use more memory as each context holds its own stack for local variables. However, I doubt the memory usage is of any problem with modern hardware, unless you're targetting mobile platforms.
AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
sonicbhoc
sonicbhoc
You're a huge help, man!
Hopefully I won't have a million more silly little questions for you, but this one has been biting at me for a while:

Can or should I put names for each variable in my declarations when registering them? I noticed in the manual that it was just the types without names when registering functions. All of my declarations for script functions specify a variable name, and I just wanted to make sure I can do that.

I haven't had a chance to compile or run my application yet; too many parts are unfinished for it to compile, so I'm kinda asking you some questions so I won't be bogged with errors when I do compile it.

Also, does AngelScript support overloaded functions or does every function need a completely unique name?

[Edited by - sonicbhoc on January 5, 2010 6:14:11 PM]
WitchLord
WitchLord
It is not necessary to specify the names of the function parameters as the names will not be used anywhere. It is not an error to do so, AngelScript will simply ignore them.

AngelScript supports overloaded functions, so you don't need to use unique names for every function.

Don't worry about asking questions. I'll do my best to answer them all.

I suggest you change your way of working. Try to always make changes in small iterations so that you can compile often without compiler errors. If you make lots of changes at the same time without being able to compile and test them during the changes you will usually end up with lots of errors to fix afterwards. It takes a lot longer to fix these errors as it will be more difficult to find given that you're not sure exactly which change it was that caused the problem.

Regards,
Andreas



AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - <a href="http://www.angelcode.com/tower" rel
sonicbhoc
sonicbhoc
Yeah, I know. The problem is that the first 6 or so modules I'm working on depend on each other a lot... so once they're done I won't have that problem anymore.

Thanks for all your help.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.