ZScript: Cannot initialize non-scalar variable

Bugs that have been investigated and resolved somehow.

Moderator: GZDoom Developers

Forum rules
Please don't bump threads here if you have a problem - it will often be forgotten about if you do. Instead, make a new thread here.
Post Reply
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

ZScript: Cannot initialize non-scalar variable

Post by Player701 »

This error message sometimes appears when trying to declare and initialize a local variable using type inference. For example:

Code: Select all

class Test
{
    void TestFunc()
    {
        let p = players[consoleplayer];
    }
}

Code: Select all

Script error, "zscript.txt:ZSCRIPT" line 5:
Cannot initialize non-scalar variable p here
On the other hand, this works fine:

Code: Select all

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
Graf Zahl
Lead GZDoom+Raze Developer
Lead GZDoom+Raze Developer
Posts: 49067
Joined: Sat Jul 19, 2003 10:19 am
Location: Germany

Re: ZScript: Cannot initialize non-scalar variable

Post by Graf Zahl »

It tries to use the source's type, which is not assignable. Unfortunately not easy to fix.
Post Reply

Return to “Closed Bugs [GZDoom]”