how exactly does the command function works in the GuiButtonCtrl objects
by hbomega · in Torque 2D Beginner · 08/28/2013 (4:48 pm) · 6 replies
i have a guiButtonCtrl object on my startscreen, when it's clicked it brings up my main menu which is a GuiSpriteCtrl object, what i want to know is how would i delete my startscreen sitting in the background when i call my main menu aftrer clicking start, and the same goes for the main menu, is it possible to have the command function call more than one function,
#2
08/29/2013 (12:46 am)
This is from the particleEditor:altCommand = "$ThisControl.getParent().updateFromChild($ThisControl); PE_EmitterEditor.updateLifeFields( false, $ThisControl.getValue(), true, false );";So seems like you can have multiple function calls in a single command.
#3
08/29/2013 (1:31 am)
Oh cool! Thanks for that, Lukas!
#4
Any way you like.
I like to use an event manager to take care of things like deleting objects because that allows you do delay deletions until the object is no longer in the update queue.
For an example of how I use EventManager objects, see the inventory module at https://github.com/RichardRanft/Torque2D/tree/inventory
Also, as Simon and Lukas have pointed out, the command is just a string that gets evaluated as if it were script. The thing to watch for here is that if you need to use quoted text you'll have to escape your internal quotes. As a bit of trivia, the T3D command edit window limits you to 1024 characters but I don't think there is actually a limit. On the other hand, I don't see any reason not to just write an onClick() or onMouseUp() (or down) handler for the control in question except for a very few cases.
08/29/2013 (10:50 am)
Quote:
what i want to know is how would i delete my startscreen sitting in the background when i call my main menu aftrer clicking start
Any way you like.
I like to use an event manager to take care of things like deleting objects because that allows you do delay deletions until the object is no longer in the update queue.
For an example of how I use EventManager objects, see the inventory module at https://github.com/RichardRanft/Torque2D/tree/inventory
Also, as Simon and Lukas have pointed out, the command is just a string that gets evaluated as if it were script. The thing to watch for here is that if you need to use quoted text you'll have to escape your internal quotes. As a bit of trivia, the T3D command edit window limits you to 1024 characters but I don't think there is actually a limit. On the other hand, I don't see any reason not to just write an onClick() or onMouseUp() (or down) handler for the control in question except for a very few cases.
#5
@Richard i'm definitely going to download your inventory and take a look under the hood, i have plans on implementing an inventory in my next project
08/29/2013 (3:14 pm)
thanks guys i'll let you know how it goes, i had a feeling that i could write my own function that handles all of the task i wanted accomplished with the command, but i wanted to know what where the alternatives and could the command actually hold more than one command, and you guys have answered them for me Thanks.@Richard i'm definitely going to download your inventory and take a look under the hood, i have plans on implementing an inventory in my next project
#6
08/29/2013 (9:03 pm)
Everything worked perfectly Thanks again
Associate Simon Love
Gui deletion
To remove any guicontrol from the screen, call Canvas.popdialog(myDialog);
I've done some tests to be sure but it seems as if you can pop a guicontrol even if it is not the topmost control on the screen.
Multiple function calls
I don't think you can specify multiple functions in the Command field of the gui but you can set Command to call a custom-made function, which would then process everything you want.
For example, let's say your Command contains "dosomestuff();", in your script somewhere, define the function as such
function dosomestuff() { loadgame(); Canvas.popdialog($MainMenu); echo("I love my life!"); }