[SOLVED]setUseMouseEvents to true from false after loading the level back again.
by Vlad I · in Torque Game Builder · 04/10/2012 (9:58 am) · 10 replies
I'm having difficulties in setting up mouse events to true after loading level back.
Imagine a room, there is carpet in front of the door way.
I have a level transition trigger object above the carpet animation.
I want the level transition only work after I clicked the carpet animation. The carpet falls down and only then you can be able to click on the level transition object.
I setMouseEvents for LevelTr3 to false.
And using this code :
So it works ok. But after I come back(load that level back) the LevelTr3 is obviously false. Waiting for the carpet animation click :D which is nowhere to be found :)
I kind of have an idea, but the solution sort of eludes me.
What would be the easy or hard way for that?
Thank you.
Imagine a room, there is carpet in front of the door way.
I have a level transition trigger object above the carpet animation.
I want the level transition only work after I clicked the carpet animation. The carpet falls down and only then you can be able to click on the level transition object.
I setMouseEvents for LevelTr3 to false.
And using this code :
function CarpetAnim :: onMouseDown (%this, %modifier, %worldPosition, %clicks)
{
if (isobject(CarpetAnim01))
{
CarpetAnim01.safeDelete();
CarpetAnim02.safedelete();
LevelTr3.setUseMouseEvents( true );
updateSceneSave(%this);
}
}I also made the carpet animation to be gone when it is clicked and when I move between the levels.So it works ok. But after I come back(load that level back) the LevelTr3 is obviously false. Waiting for the carpet animation click :D which is nowhere to be found :)
I kind of have an idea, but the solution sort of eludes me.
What would be the easy or hard way for that?
Thank you.
About the author
#2
if (CarpetAnim == deleted)?
Then I'd probably could have it worked with onLevelLoaded.
04/11/2012 (12:25 am)
Is there a way to check the object's status? Something like if (CarpetAnim == deleted)?
Then I'd probably could have it worked with onLevelLoaded.
#3
You can use:
04/11/2012 (5:30 am)
Vlad,You can use:
if(isObject(CarpetAnim) == false)to check if the object exists. It sounds to me like the useMouseEvents parameter is not being saved in your updateSceneSave method.
#4
I'm having advanced script error in your line of code (line 3), when I use this:
04/11/2012 (6:22 am)
Hi Patrick.I'm having advanced script error in your line of code (line 3), when I use this:
function levelTranOnce :: OnLevelLoaded
{
if(isObject(CarpetAnim) == false)
{
LevelTr3.setUseMouseEvents( true );
updateSceneSave(%this);
}
}
function CarpetAnim :: onMouseDown (%this, %modifier, %worldPosition, %clicks)
{
if($cursorActive == false)
{
//exit the function.
return;
}
if (isobject(CarpetAnim01))
{
CarpetAnim01.safeDelete();
CarpetAnim02.safedelete();
LevelTr3.setUseMouseEvents( true );
updateSceneSave(%this);
}
}
#6
It deletes the carpet, then able to press on the levelTr3 trigger , I come back no carpet and mouse events is off on leveTr3. But if I use isobject as CarpetAnim instead of CarpetAnim01 object :
Then I run the game (level) loads up straight foward with out carpet and you click on the levelTr3 and move between the levels.
04/11/2012 (7:06 am)
:) you are right. But it still doesn't turn on mouse events when I go back to that level. I'm using this :function levelTranOnce :: OnLevelLoaded(%this)
{
if (isobject(CarpetAnim01) == false)
{
LevelTr3.setUseMouseEvents( true );
updateSceneSave(%this);
// }
//else {LevelTr3.setUseMouseEvents( true );
// updateSceneSave(%this);
}
}
function CarpetAnim :: onMouseDown (%this, %modifier, %worldPosition, %clicks)
{
if($cursorActive == false)
{
//exit the function.
return;
}
if (isobject(CarpetAnim01))
{
CarpetAnim01.safeDelete();
CarpetAnim02.safedelete();
LevelTr3.setUseMouseEvents( true );
updateSceneSave(%this);
}
}It deletes the carpet, then able to press on the levelTr3 trigger , I come back no carpet and mouse events is off on leveTr3. But if I use isobject as CarpetAnim instead of CarpetAnim01 object :
function levelTranOnce :: OnLevelLoaded(%this)
{
if (isobject(CarpetAnim) == false)
{...Then I run the game (level) loads up straight foward with out carpet and you click on the levelTr3 and move between the levels.
#7
checks straight forward and finds that previously the Carpet was saved (marked) as deleted object, so it deletes quickly. But this all happens on leveLoaded hence the levelTr3 waits for the Carpet to be deleted. If you know what I mean.
Do you think I should use onUpdate? or smth. else
04/11/2012 (7:20 am)
I can only think of the game loading very fast the Carpet then checkSceneschecks straight forward and finds that previously the Carpet was saved (marked) as deleted object, so it deletes quickly. But this all happens on leveLoaded hence the levelTr3 waits for the Carpet to be deleted. If you know what I mean.
Do you think I should use onUpdate? or smth. else
#8
You could also try replacing .safeDelete() with just a hard .delete(). I've occasionally run into timing issues because .safe.Delete basically schedules out the delete by 1, and code that checks if it exists can execute before that happens.
04/13/2012 (9:20 am)
Well, try adding a line to echo out the return from isobject(CarpetAnim01). Also, you don't need to explicitly check if it's == to true or false. It returns a boolean value, so simple saying if(isobject(CarpetAnim01)) should suffice.You could also try replacing .safeDelete() with just a hard .delete(). I've occasionally run into timing issues because .safe.Delete basically schedules out the delete by 1, and code that checks if it exists can execute before that happens.
#9
Is there a way to make objects receive clicks only on the top most one? e.g. first layered?
04/14/2012 (6:44 am)
Harry I tried it your way it doesn't work.Is there a way to make objects receive clicks only on the top most one? e.g. first layered?
#10
04/14/2012 (6:59 am)
Thank you all for your help. I solved the problem. The issue was in another script which was saving all the deleted objects into a file. onLevelLoaded was reading out the data from it on the start , I needed to add this line there to make it work.%this.setUseMouseEvents( true );
Torque 3D Owner Harry Durnan