This code doesn't work (setVisible)
by baylor wetzel · in Torque Game Builder · 06/02/2009 (5:30 pm) · 1 replies
On the main map, click a city. That loads the city map, which takes a while, so display "Loading" until it's done. Unfortunately, Loading" never displays - we sit on the old screen for a while and then suddenly the new screen pops up. This *only* happens if i call safeLoadLevel *after* the setVisible call - otherwise the visibility thing works perfectly. Seems odd that the future should prevent the change the past
Any idea how to fix this?
It seems to me that loadingLabel.visible = true; (or setVisible, which i originally used) should work independent of what line comes *after* it. If i comment out the next line (safeLoadLevel("orlandoLevel");), it works just fine, so apparently the future is interfering with the present
In case anyone wonders why i have a function called safeLoadLevel, it's because TGB's loadLevel can't be used within a function - doing so causes the game to crash (presumably because it's unloading the level that called the function while the function is still running). This error drove me nuts for weeks but i've been using this solution for the last two years (hence references to things like $runWithEditors) and it's never had a problem
Any idea how to fix this?
function orlandoMapButton::onClick(%this)
{
echo("Map: chose Orlando");
loadingLabel.visible = true; // <--- THIS DOESN'T WORK
safeLoadLevel("orlandoLevel");
}
function safeLoadLevel(%levelName)
{
%debuggingLevelLoads = false;
if (%debuggingLevelLoads)
echo("Being asked to load the level " @ %levelName);
//--- To load the level, we need its fully qualified name
%levelName = getLevelFQN(%levelName);
if (%debuggingLevelLoads) echo("Full level name: " @ %levelName);
//--- Let's make sure this level actually exists
if (!assertLevelExists(%levelName)) return false;
//--- Coming off a splash screen, the screen don't show unless we do this
Canvas.setContent(mainScreenGui);
Canvas.setCursor(DefaultCursor);
//--- We can schedule any time we want, including 0
//--- No matter what the value, it causes TGB to wait until we've
//--- exited this recursion down the call stack, which is all we
//--- really want
sceneWindow2D.schedule(0, loadLevel, %levelName);
if ($runWithEditors)
{
Canvas.pushDialog(LBPlayLevelGui);
}
}It seems to me that loadingLabel.visible = true; (or setVisible, which i originally used) should work independent of what line comes *after* it. If i comment out the next line (safeLoadLevel("orlandoLevel");), it works just fine, so apparently the future is interfering with the present
In case anyone wonders why i have a function called safeLoadLevel, it's because TGB's loadLevel can't be used within a function - doing so causes the game to crash (presumably because it's unloading the level that called the function while the function is still running). This error drove me nuts for weeks but i've been using this solution for the last two years (hence references to things like $runWithEditors) and it's never had a problem
About the author
Torque 3D Owner Ted Southard