[Solved] Error: can't call play function from ui context

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
Player701
 
 
Posts: 1636
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

[Solved] Error: can't call play function from ui context

Post by Player701 »

Hi. Found a similar issue mentioned here, but looking further down the thread I couldn't find a solution, and that thread is closed, so posting in a new thread.

Problem: I have the following ZScript (minimal example to demonstrate)

Code: Select all

class TestHud : BaseStatusBar
{
    override void Draw(int state, double TicFrac)
    {
        Super.Draw(state, TicFrac);
        Test();
    }
    
    private void Test()
    {
    }
}
GZDoom 3.6.0 complains when parsing it:

Code: Select all

Script error, "zscript.txt:ZSCRIPT" line 6:
Can't call play function test from ui context
Does anyone know how to fix this? ZZYZX provided a solution further down the thread I linked above:
ZZYX in another thread wrote:...ok, that's extremely weird. Are statusbars not ui? Why? I see BaseStatusBar is declared as ui but it doesn't work apparently.

Anyway, this particular issue can be fixed by explicitly marking your draw function as ui (e.g. protected ui void DrawFullScreenStuffCustom).
Unfortunately, it doesn't work; when I change "private void Test()" to "private ui void Test()", GZDoom says:

Code: Select all

Script error, "zscript.txt:ZSCRIPT" line 9:
Unexpected identifier
Expecting ';' or ','
If I try to put the "ui" keyword on the class itself, GZDoom also doesn't seem to like it.

If anyone knows what I should do, any kind of help will be greatly appreciated :)
Last edited by Player701 on Sun Oct 14, 2018 6:51 am, edited 1 time in total.
User avatar
Apeirogon
Posts: 1605
Joined: Mon Jun 12, 2017 12:57 am

Re: Error: can't call play function from ui context

Post by Apeirogon »

Did you add {version "2.4"} without {} to the top of you zscript file?
User avatar
m8f
 
 
Posts: 1445
Joined: Fri Dec 29, 2017 4:15 am
Preferred Pronouns: He/Him
Operating System Version (Optional): Manjaro Linux
Location: Siberia (UTC+7)
Contact:

Re: Error: can't call play function from ui context

Post by m8f »

Just tried, the code

Code: Select all

class TestHud : BaseStatusBar
{
    override void Draw(int state, double TicFrac)
    {
        Super.Draw(state, TicFrac);
        Test();
    }

    private ui void Test()
    {
    }
} 
runs just fine.

I tried to reproduce the error you described, for me it happens if I misspell 'ui'.
User avatar
Player701
 
 
Posts: 1636
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Error: can't call play function from ui context

Post by Player701 »

Oh crap, I completely forgot about this version stuff. Now it seems to work fine. Thanks a lot...
Post Reply

Return to “Scripting”