Advertisement

Temporary array as argument

Started by April 26, 2016 08:19 PM
5 comments, last by WitchLord 8 years, 7 months ago

This is my first post. I read the FAQ, but if I'm violating any etiquette, please let me know.

I am having trouble with Angelscript syntax. Is there any way to create a temporary array? I'd like to pass one to a class constructor without creating an array variable beforehand. That way the array only exists for the purpose of object construction.

I've posted my test class below, along with how I'm currently accomplishing this by declaring an array before the object creation, and also what I'm trying to do.


class MyObj
{
    MyObj(const uint[]@ vals)
    {
        _values = vals;
    }

    const uint[]@ get_values() const
    {
        return _values;
    }

    void set_values(const uint[]@ vals)
    {
        _values = vals;
    }

    uint[] _values;
}

// How I'm doing this now
uint[] input = { 20, 40, 60, 80, 100 };
MyObj instance(input);


// How I would like to do it, if possible
MyObj instance( { 20, 40, 60, 80, 100 } );

Hi jackbanion. Welcome to the forum :)

Anonymous arrays currently require that you specify the type of the initialization list. The compiler is not yet capable of determining the type automatically by looking at what the list is used for.

MyObj instance( uint[] = { 20, 40, 60, 80, 100 } );
 
// I'm actually not entirely sure right now if the to-be deprecated syntax uint[] works. If not try this instead
MyObj instance( array<uint> = { 20, 40, 60, 80, 100 } );

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Advertisement

Thanks for the reply Andreas.

I am writing Angelscript code on an embedded display that supports it, but I believe it uses an older version of Angelscript. It doesn't seem to accept the array<uint> = { ... } line or the uint[] = { ... } line. I know it is an older version because there also isn't support for access modifiers (public/private) in the script classes. Or maybe the array<> template existed in this version and the manufacturer didn't register support for it.

Do you know of any other way to do this with the non-array<> syntax? When I use uint[] = { ... }, I get a script compile error saying:

ERR : Expected '('
I think I'm just going to be stuck doing the two-line method.

Do you have any idea of which version of AngelScript that is running on the embedded display? Support for anonymous arrays were introduced in version 2.28.2, released on March 18th, 2014.

I checked now, the syntax MyObj instance( uint[] = { 20, 40, 60, 80, 100 } ); isn't supported even in the current version. I'll look into adding that.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

I am not sure of the exact version. Let me check with the manufacturer, and maybe even prompt them to upgrade to the latest version!

I got a response on the version, 2.18.1. Does this mean there's no hope for what i'm trying to accomplish short of having the manufacturer support a more recent version of AngelScript?

Advertisement

Yes, unfortunately. You'll just have to continue doing what you're already doing, i.e

// How I'm doing this now
uint[] input = { 20, 40, 60, 80, 100 };
MyObj instance(input);

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