Author Topic: Custom play GUI crashing Blockland  (Read 2727 times)

Code: [Select]
if ( !isObject( "testPlayGUI" ) )
{
new gameTSCtrl( "testPlayGUI" )
{
visible = true;
noCursor = true;
};
}

if ( !isObject( "energyHUD" ) )
{
new guiSwatchCtrl( "energyHUD" )
{
position = "0 0";
extent = "175 24"; // 138 24

visible = true;
color = "0 0 0 0";
};

for ( $index = 0 ; $index < 10 ; $index++ )
{
$obj = new guiBitmapButtonCtrl()
{
position = 37 + 14 * $index SPC 0;
extent = "12 24";

visible = true;
mColor = "25 55 55 127";

text = "";
bitmap = "./energy";
};

energyHUD.add( $obj );
energyHUD.cell[ $index ] = $obj;
}

energyHUD.text = new guiMLTextCtrl()
{
position = "0 0";
extent = "33 25";

visible = true;
text = "<font:digital-7 mono:25><color:193737>000";
};

$index = "";
$obj = "";

energyHUD.add( energyHUD.text );
testPlayGUI.add( energyHUD );
}

function testPlayGUI::onWake( %this )
{
playGui::onWake( %this );
%res = getRes();

energyHUD.position = getWord( %res, 0 ) - 187 SPC getWord( %res, 1 ) - 32;
}

function testPlayGUI::onSleep( %this )
{
playGui::onSleep( %this );
}

If I execute this code after the game started, doing this works: canvas.setContent(testPlayGUI);
Otherwise, if it executes during the add-on loading process, Blockland simply crashes when I enter the above into the console.

use PlayGUI::OnWake(%this) to execute the testPlayGUI?

Why do you need a custom play GUI? Why not just add to the one that's there?

Why do you need a custom play GUI? Why not just add to the one that's there?

Because I need a limited set of HUD controls, excluding defaults and additions from other add-ons.

Because I need a limited set of HUD controls, excluding defaults and additions from other add-ons.
Just delete some and modify the add function?

Just delete some and modify the add function?

Creating a different GUI instead is 100% less hackish.

Why do you need a custom play GUI? Why not just add to the one that's there?
Just delete some and modify the add function?
If I were to use the current one for whatever I plan on making. I'd end up deleting everything on it.

Isn't their a No HUD version of the GUI? I am sure you can build on that one, Port.

If it executes fine after the game loads, then why not execute it after the game loads? Either through a schedule, mainMenu::onWake, or some sort of onFinishedLoading function if such a function exists?

 The onWake and onSleep functions may be causing your problem.
« Last Edit: July 28, 2012, 01:06:41 AM by elm »

Isn't their a No HUD version of the GUI? I am sure you can build on that one, Port.
And then when you take a screenshot... lol

I've done some further testing, and it seems like the game has behavior like this by default:

Code: [Select]
package test_package
{
        function guiControl::onAdd( %this )
        {
                parent::onAdd( %this );
                %this.initialMemberCount = %this.getCount();
        }
        
        function guiControl::onWake( %this )
        {
                %count = %this.getCount();
               
                if ( %count !$= %this.initialMemberCount )
                {
                        crash();
                }
                
                %this.initialMemberCount = %count;
                parent::onWake( %this );
        }
};

activatePackage( "test_package" );

And then when you take a screenshot... lol
Nah but you could rip it off and rename it into your own GUI? Meh.

Nah but you could rip it off and rename it into your own GUI? Meh.
I'm sure he's already got something like that, he just needs the functions.

It seems that I either need to add all the children when the GUI wakes (which would be bad due to having to recreate everything if it was awake earlier) or add them while creating the GUI (which would be bad due to having to hardcode everything).