• 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
jetro

Constants and enums

9 posts in this topic

Hi, just asking if there's any way to express constants and enumerations, both globally and for classes and objects? I noticed it's possible to state a variable (property) as const, but it still needs to be physically present. For example, I have C++ code like this:
class Foo
{
public:
    enum FLAGS
    {
        BAR  = (1 << 0),
        GORP = (1 << 1),
        // ... and so on
    };
    // ...
};

When exposing the Foo class API to scripting, I'd like to expose the possible flags as well to be used with methods. As I see it, currently I'd have to create "proxy" global const variables holding the same values, and then register them as global properties (with prefixed names or so). Or is it possible to introduce class specific constant values in some better way? What about static class member fields?
0

Share this post


Link to post
Share on other sites
You can add enums and constants by building a script section with the declarations and adding it to the module that you're building.


const char *constants = "const int flag1 = 0; const int flag2 = 1; const int flag3 = 2; // etc";

engine->AddScriptSection("module", "constants", constants, strlen(constants));
engine->AddScriptSection("module", "loaded script", script, strlen(script));
engine->Build("module", 0);



I may add some way of registering enums and constants directly through other Register functions but there are a lot of other things I judge more important.
0

Share this post


Link to post
Share on other sites
Thanks for the reply.

That's what I ended up doing then, with adding class specific prefix to the values which are related to some classes.

All added script sections get deleted on a Discard call though, although registered object types, methods, functions and properties seem to remain registered.

Basically I want to keep the same base with the different registered addon APIs (containing script section adds to get the "enums"), and then load some specific script file on top of that which can be changed.

For now I ended up reinitializing the whole scripting engine when I load a new script.

Also the solution of adding script sections to make "enums" has the problem that it screws up the line numbers for debugging purposes related to the actual loaded script file. This is easily "fixed" by not adding newlines at all for the initial script sections, in which case only the columns for the first line are wrong (which is most probably a comment or something valid anyway). Would it be possible to get line numbers local to the added section name?

P.S. Other small things: I also find it a bit annoying having to write explicit type conversions in script code. For example, some func returns an int and another takes in a float for a coordinate, and I'd like to pass the int directly to the func. Now I have to write float(var) in all cases like this. Also requirement on defining bits explicitly with a hex value (0x) felt a bit stupid. :) And last, the debug libs keep making a huge stats.txt (and bunch of other __*.txt files), so I stopped using the debug lib for now.

Edit: Not to sound too negative, I thought that I should probably mention that apart from the small issues I'm having, I have found out AS quite easy and nice to use so far (with the few small tests I have been making).
0

Share this post


Link to post
Share on other sites
Critiques are good :)

Actually the script sections get deleted when you call Build(). Because there is no sense in keeping two copies (albeit in different form) of the scripts.

I've been thinking about a way to make the engine configuration more dynamic. Currently there is no way to unregister functions/objects/properties. I'll probably end up doing something similar to the modules, or create unregister functions. My goal is that it should be possible to dynamically load plug-ins that get registered with the engine and then unloaded when no longer needed. Allowing for the registration of constants and enums like this makes a lot more sense in this case so I'll probably add that as well.

I've been aware of a problem with the wrong line numbers for a while, but haven't found the time to fix them. What you tell me gives me a little more insight as line numbers are supposed to be local to the script sections. If they are not then something is definitely wrong. I'll see if I put more effort into fixing this.

I may change the way implicit conversions are treated for future versions. I was thinking that limiting the implicit conversions would help the script writer avoid difficult to find bugs, but I may just have hindered the ease of development. I'll have to think about this one.

You can avoid the creation of the stats.txt and the __*.txt files by undefining the precompiler flag AS_DEBUG from the project settings. These files are used by me to verify the bytecode.

Thanks for letting me know that you like the library after all. That was an relief (I mean it).

I only ask you to have patience because I currently have almost no time at all to work on AS, as I'm working on a paying project right now. In a couple of months I should be back to the normal rythm of releases.
0

Share this post


Link to post
Share on other sites
Sounds good. I perfectly understand the issue of having not enough time, don't worry. :)

I also have been wondering have you put up much thought to possible exploits through the scripting interface? AS gives a bit more direct interface to program execution by having pointers and such, which are usually banned in scripting side as is. Although to me it seems there's some validation regarding pointer handling. For the application I'm currently making this is not really an issue though, I'm just interested if you have been focusing on this side as well. That is, assuming that application itself doesn't sloppily open holes in the functionality it exposes, how secure do you think AS is against intentional misuse of scripting?
0

Share this post


Link to post
Share on other sites
Pointers aren't a problem because (AFAIK at least), AS doesn't allow the modification or creation of pointes. You can only pass them around between functions. This is also the reason why arrays are a bit more complex.
0

Share this post


Link to post
Share on other sites
Gyrbo is correct.

I'm very concious of security issues and I try my best to make AngelScript as secure as possible. As far as I know, AngelScript itself doesn't expose any way of exploiting either the application or operative system. The script writer can only do what the host application allows him to do.
0

Share this post


Link to post
Share on other sites
Quote:
Original post by jetro
Also the solution of adding script sections to make "enums" has the problem that it screws up the line numbers for debugging purposes related to the actual loaded script file. This is easily "fixed" by not adding newlines at all for the initial script sections, in which case only the columns for the first line are wrong (which is most probably a comment or something valid anyway). Would it be possible to get line numbers local to the added section name?


I found a little time to take a look at the problem with the line numbers and I did find a small bug in the as_scriptnode.cpp file. To fix it do the following modification:


void asCScriptNode::UpdateSourcePos(int pos, int length)
{
// Add this line to the beginning of the function
if( pos == 0 && length == 0 ) return;

// No more changes after that


{EDIT} I fixed an error in the bug fix {/EDIT}

This fixes the bug where some errors always reports the position on row 1 and column 1. Though from what you describe this isn't exactly the problem you're having.

I was trying to reproduce the problem as you described it, but I didn't have any success in that. One script section shouldn't affect the line numbers in another, unless there is a really serious bug somewhere.

Could you test the fix and tell me if it also fixes your problem?

[Edited by - WitchLord on July 27, 2004 7:38:47 AM]
0

Share this post


Link to post
Share on other sites
I tried to apply that fix, but it resulted in the addon bstr registration starting to fail.

Assertion failed on expression: r >= 0
File: bstr.cpp, Line: 29

r equals to -12 at that point, which seems to be asINVALID_TYPE.

I tried to reproduce the problem I described, and for some reason couldn't get it anymore. Apparently I have changed something on the way in my app/scripting init code which fixed the issue for me, or that I have just done something wrong before. So you can leave this issue for now, I guess, since there's no test case for it. :)
0

Share this post


Link to post
Share on other sites
That there isn't a test case for just proves that I haven't tested it yet. ;)

I'll see if I can find a problem with registering bstr when using the bug fix.

OK. The problem did exist. I have no idea why you weren't able to reproduce it though. The problem was that UpdateSourcePos() didn't update when pos == 0, which is in fact a valid value. Change the previous bug-fix to be as follows:

if( pos == 0 && length == 0 ) return;

The difference is the && instead of the ||. Note, I've updated the bug-fix above.
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