ZScript: Cannot initialize non-scalar variable

Is there something that doesn't work right in the latest GZDoom? Post about it here.

Moderator: Developers

Forum rules
Please construct and post a simple demo whenever possible for all bug reports. Please provide links to everything.

If you can include a wad demonstrating the problem, please do so. Bug reports that include fully-constructed demos have a much better chance of being investigated in a timely manner than those that don't.

ZScript: Cannot initialize non-scalar variable

Postby Player701 » Sun Nov 18, 2018 3:33 pm

This error message sometimes appears when trying to declare and initialize a local variable using type inference. For example:
Code: Select allExpand view
class Test
{
    void TestFunc()
    {
        let p = players[consoleplayer];
    }
}

Code: Select allExpand view
Script error, "zscript.txt:ZSCRIPT" line 5:
Cannot initialize non-scalar variable p here

On the other hand, this works fine:
Code: Select allExpand view
class Test
{
    void TestFunc()
    {
        PlayerInfo p = players[consoleplayer];
    }
}

It appears this happens when the declared type of the assigned value is prefixed with "@". For example, some global variables (in "struct _") are declared like this.
User avatar
Player701
You are now breathing manually.
 
Joined: 13 May 2009
Location: Russian Federation
Discord: Player701#8214

Re: ZScript: Cannot initialize non-scalar variable

Postby Graf Zahl » Sun Nov 18, 2018 3:51 pm

It tries to use the source's type, which is not assignable. Unfortunately not easy to fix.
User avatar
Graf Zahl
Lead GZDoom Developer
 
Joined: 19 Jul 2003
Location: Germany


Return to Bugs

Who is online

Users browsing this forum: No registered users and 2 guests