Code: Select all
version "2.5"
#include "ZScript/ThermalImp.zc"
class MyGlobalVariables : Thinker
{
int prevstate;
double start_time ;
MyGlobalVariables Init()
{
PlayerInfo p = players[ consoleplayer ];
prevstate = Cvar.GetCVar( "gl_thermalcam", p ).GetInt();
start_time = 0 ;
ChangeStatNum(STAT_STATIC);
return self;
}
static MyGlobalVariables Get()
{
ThinkerIterator it = ThinkerIterator.Create("MyGlobalVariables", STAT_STATIC);
let q = MyGlobalVariables(it.Next());
if (q == null)
{
q = new("MyGlobalVariables").Init();
}
return q;
}
}
class ThermalCamHandler : EventHandler
{
override void RenderOverlay( RenderEvent e )
{
PlayerInfo p = players[ consoleplayer ];
let g = MyGlobalVariables.Get(); //Causes the error: "Can't call play function get from ui context"
double timer = gametic + e.fracTic ;
if( Cvar.GetCVar( "gl_thermalcam", p ).GetInt() == 1 )
{
if( g.prevstate == 0 )
{
g.start_time = timer ;
g.prevstate = 1 ;
}
Shader.SetEnabled( p, "ThermalCam", true );
}
else
{
if( g.prevstate == 1 )
{
g.start_time = timer ;
g.prevstate = 0 ;
}
Shader.SetEnabled( p, "ThermalCam", false );
}
double timeleft = 1.0 - ( timer - g.start_time );
if( timeleft > 0 )
{
Shader.SetUniform1f( p, "Shutter", "countdown", timeleft * 39 + 1 );
Shader.SetEnabled( p, "Shutter", true );
}
else Shader.SetEnabled( p, "Shutter", false );
}
}
That's the theory except that the line 'let g = MyGlobalVariables.Get();' causes an error: "Can't call play function get from ui context". Which if it is in fact global, means I'm doing something wrong. Or should I just stick to using CVars as I've done before?