Loading Bar Gui (GuiProgressControl) Help Needed
by Orion the Hunter · in Torque Game Builder · 01/30/2013 (11:10 am) · 10 replies
function NowLoadingGui::onWake()
{
schedule(1000, 0, "startLoading");
echo("Loading…");
}
function NowLoadingGui::onSleep()
{
echo("Done.");
schedule(250, 0, "PlaceInPos");
}
function startLoading()
{
schedule(600, 0, "L1");
schedule(650, 0, "L2");
schedule(600, 0, "L3");
schedule(700, 0, "L4");
schedule(1000, 0, "L5");
schedule(700, 0, "L6");
schedule(600, 0, "L7");
schedule(1000, 0, "L8");
schedule(1000, 0, "L9");
schedule(2000, 0, "FinalStageLoad");
}
function L1()
{
LoadText.setText($L1);
}
function L2()
{
LoadText.setText($L2);
}
function L3()
{
LoadText.setText($L3);
}
function L4()
{
LoadText.setText($L4);
}
function L5()
{
LoadText.setText($L5);
}
function L6()
{
LoadText.setText($L6);
}
function L7()
{
LoadText.setText($L7);
}
function L8()
{
LoadText.setText($L8);
}
function L9()
{
LoadText.setText($L9);
}
function onfinalStageLoadProgress(%progress)
{
LoadBar.setValue(%progress);
Canvas.repaint();
}
function finalStageLoad()
{
_newGame();
readFile();
}
$L1 = "Collecting components\nand scripts...";
$L2 = "Creating spawn points...";
$L3 = "Loading data...";
$L4 = "[Points...]";
$L5 = "[Lives...]";
$L6 = "[Health...]";
$L7 = "[Position...]";
$L8 = "[Level...]";
$L9 = "Cleaning up...";You just saw my "Loading Gui" script. I searched about the Torque 3D Loading bar code in missionLoad.cs (in scripts/server) and I relativized it to my code. Unfortunately, I think the Torque 3D MIT license codes (or T3D codes in general) aren't exactly compatible with T2D. The line,
LoadBar.setValue(%progress);
Is supposed to set it to the value of the loading progress, but how do I make it so the game is constantly updating? I know my question is a bit confusing because I, myself, have little understanding of what the heck I'm doing. :P I'll put it out flat: how do I make a loading bar using a GuiProgressControl?
#2
01/30/2013 (3:45 pm)
When I looked through the T3D file it didn't need to be called and I tried putting Canvas.repaint in to the finalStageLoad() function. Anywho, I just made it in to a plain old function and it didn't work. Is there something that gives you a percentage of the progress a function has made to completing it's job?
#3
01/30/2013 (5:33 pm)
Did you look in both the server and client missionDownload.cs files? They are slightly different and each handles essentially half of the progress bar update setup.
#4
Thanks!
01/31/2013 (6:45 am)
Yes, I took a look a both. I just don't get how it works. :-/ How 'bout this: can someone just make a bar from scratch for me to look at? That would be AWESOME.Thanks!
#5
Ex:
Then adjust your setValue up by .1 (assuming you have 10 total) each time, otherwise do a division equation for your instances so.. ( 1/9, 2/9, etc..)
There are alternatives of course, but based on what you have set up so far, this should be sufficient.
01/31/2013 (7:46 am)
The above method would work if you just simply call your GuiProgessControl setValue within your L functions.Ex:
function L1()
{
LoadText.setText($L1);
LoadBar.setValue(.1);
Canvas.repaint(); //may not be needed
}Then adjust your setValue up by .1 (assuming you have 10 total) each time, otherwise do a division equation for your instances so.. ( 1/9, 2/9, etc..)
There are alternatives of course, but based on what you have set up so far, this should be sufficient.
#6
01/31/2013 (9:28 am)
Thanks! I think it shouldn't give me any more problems. :)
#7
My full code. I'm getting an error...
01/31/2013 (10:35 am)
//--- OBJECT WRITE BEGIN ---
function NowLoadingGui::onWake()
{
startLoading();
echo("Loading�");
loadbar();
}
function NowLoadingGui::onSleep()
{
echo("Done.");
schedule(250, 0, "PlaceInPos");
}
function startLoading()
{
schedule(700, 0, "L1");
schedule(750, 0, "L2");
schedule(700, 0, "L3");
schedule(700, 0, "L4");
schedule(1000, 0, "L5");
schedule(700, 0, "L6");
schedule(700, 0, "L7");
schedule(1000, 0, "L8");
schedule(900, 0, "L9");
schedule(1000, 0, "L10");
schedule(1000, 0, "L11");
schedule(800, 0, "L12");
schedule(700, 0, "L13");
schedule(700, 0, "L14");
schedule(700, 0, "L15");
schedule(800, 0, "L16");
schedule(1000, 0, "L17");
}
function L1()
{
LoadText.setText($L1);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L2()
{
LoadText.setText($L2);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L3()
{
LoadText.setText($L3);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L4()
{
LoadText.setText($L4);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L5()
{
LoadText.setText($L5);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L6()
{
LoadText.setText($L6);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L7()
{
LoadText.setText($L7);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L8()
{
LoadText.setText($L8);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L9()
{
LoadText.setText($L9);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L10()
{
LoadText.setText($L10);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L11()
{
LoadText.setText();
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L12()
{
LoadText.setText($L12);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L13()
{
LoadText.setText($L13);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L14()
{
LoadText.setText($L14);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L14()
{
LoadText.setText($L15);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L16()
{
LoadText.setText($L16);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L17()
{
LoadText.setText($L17);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function LoadBar()
{
if($loadProgress < 1.001)
{
LoadBar.setValue($LoadProgress);
}
else
{
finalStageLoad();
}
}
function finalStageLoad()
{
_newGame();
readFile();
Canvas.repaint();
}
$L1 = "Compiling componentsnand scripts...";
$L2 = "Creating spawn points...";
$L3 = "Loading data...";
$L4 = "[Points...]";
$L5 = "[Lives...]";
$L6 = "[Health...]";
$L7 = "[Position...]";
$L8 = "[Level...]";
$L9 = "Loading GUIs";
$L10 = "[Windows...]";
$L11 = "[Buttons...]";
$L12 = "[Images...]";
$L13 = "Sharpening Pencils andnpens...";
$L14 = "Readying erasers...";
$L15 = "Stacking paper...";
$L16 = "Drying ink...";
$L17 = "Cleaning up...";My full code. I'm getting an error...
Quote:/game/gui/NowLoadingGui.gui Line: 171 - parse error
>>> Advanced script error report. Line 171.
>>> Some error context, with ## on sides of error halt:
LoadBar();
}
function L9()
{
LoadText.setText($L9);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L10()
{
LoadText.setText($L10);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L11()
{
LoadText.setText($11);
##$##Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L12()
{
LoadText.setText($L12);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L13()
{
LoadText.setText($L13);
$Loadprogress = $LoadProgress + 0.05;
LoadBar();
}
function L14()
>>> Error report complete.
#8
LoadText.setText($11);
should be...
LoadText.setText($L11);
Also...
on your loadBar function.. you're better off stating your less than as this...
if($loadProgress <= 1)
(It should never be more than 1, since 1 is 100%... and adding the decimals.. is well.. not clean code)
And.. all your functions seem to producing the same result in the end...
$Loadprogress = $LoadProgress + 0.05;
Either you have 2 variable here and are not adding correctly.. or, you're bound to run into an error (or.. it'll produce the same result over & over again..) I would declare $loadProgress = 0; somewhere in initialization before the script is called.. then simply do $loadProgress += 0.05; on each func call.
01/31/2013 (10:42 am)
I'm assuming here..LoadText.setText($11);
should be...
LoadText.setText($L11);
Also...
on your loadBar function.. you're better off stating your less than as this...
if($loadProgress <= 1)
(It should never be more than 1, since 1 is 100%... and adding the decimals.. is well.. not clean code)
And.. all your functions seem to producing the same result in the end...
$Loadprogress = $LoadProgress + 0.05;
Either you have 2 variable here and are not adding correctly.. or, you're bound to run into an error (or.. it'll produce the same result over & over again..) I would declare $loadProgress = 0; somewhere in initialization before the script is called.. then simply do $loadProgress += 0.05; on each func call.
#9
Functionally identical, but the first method (to agree with Doc) is cleaner and might actually be faster in TorqueScript.
Also, any time you do anything with decimal values it is best to ensure that all values are decimal values. For example:
01/31/2013 (11:57 am)
$LoadProgress += 0.05; // add 0.05 to $LoadProgress $LoadProgress = $LoadProgress + 0.05; // add 0.05 to $LoadProgress
Functionally identical, but the first method (to agree with Doc) is cleaner and might actually be faster in TorqueScript.
Also, any time you do anything with decimal values it is best to ensure that all values are decimal values. For example:
if ( $LoadProgress <= 1.0 ) // instead of just 1TorqueScript occasionally does "funny" things otherwise.
#10
It just drives me bonkers not seeing things the same case defined throughout variables.
01/31/2013 (12:30 pm)
Ah yes, TorqueScript is not Case Sensitive.. however, I still find it good practice to keep all variable Case Sensitive, just as a matter of coding practice. Perhaps spent too long dealing with C++.It just drives me bonkers not seeing things the same case defined throughout variables.
Torque Owner Max Kielland
MK Development
[EDIT]
Hmm, from where is onfinalStageLoadProgress() called?!? Have you put an echo in all functions to see in what order they are called or if they are called at all?