### Newbie Questions

2D version of the Torque engine.

#### Newbie Questions

Posts: 2
Joined: Tue Jul 25, 2017 8:23 am
Hello torque community! new member here and i was advised that i should post here!! i originally posted in https://www.garagegames.com/community/f ... ead/143625 last night and i was tired as fuck and typing on a phone, here i am on a computer so i can try to make more sense!

So with Torque 2D and all the internet tutorials avaliable i started my process!! i did the Getting Started Guide, The Behavior Tutorial, Intro to the GUI 1-2 and thats where the real fun begins

Deciding to recreate the Asteroid Game and the Fish Game into a single project! (As a game Compilation) i have successfully created the main menu screen, a console for debugging and i recreated the Asteroid Game and made some changes, this is where my problems began!! so i kept at it without making any blog posts and managed to implement some of the ideas i had (Albiet VERY poorly in my opinion)

For Instance I wanted to create a "brake" for the Asteroid Ship Game (Whenever you collide with an Asteroid you die so i figured i needed a way stop!)
Working Code (After some experimentation)

function PlayerShip::brake(%this){	//First thing we want is to cancel the Thrust Schedule!	cancel(%this.thrustschedule);	//Trying to remove Linear Impulse to Stop our ship!, still learning code so thats why i have two lines of script here	cancel(%this.applyLinearImpulse);	%this.removeLinearImpulse(%ThrustVector, "0 0"); 		//Adding Damping to the Linear Velocity wich slows the ship when "s" is pressed	%this.setLinearDamping(5.8);	//We have changed the Angular Damping to try and get a different turn speed while slowing down	%this.setAngularDamping(2.0);	//we set isThrusting to false to indicate that we are no longer thrusting.	//Next time we hit 'w', our accelerate function will use a bigger acceleration boost to get us going faster!	%this.isThrusting = false;}

Is that a good break? all i did was grab the Accelerate Function and tried to make an opposite of the code so that instead of accelerating we are stopping! (and i admit it works, im just not sure it is the most easiest way for it to work?

My second issue is the GUI, The Intro To The GUI (making a main menu) didnt really explain the setting up of the buttons too well! i tried to create a exit button for the Asteroid Game to Return me to the main menu and creating the TAML file seemed simple enough, however whenever i tried to add it to scene window in the Main.CS with

CreatecommandsAbove

//Trying to get the Dialog for the Restart ButtonmySceneWindow.add( TamlRead("./gui/AsteroidDialog.gui.taml");mySceneWindow.pushdialog(AsteroidDialog);new ScriptObject(InputManager);mySceneWindow.addInputListener(InputManager);InputManager.Init_controls();//the end of function MyModule::Create}

TAML File
<GuiSpriteCtrl    Name="AsteroidDialog"    Profile="GuiToolboxProfile"    HorizSizing="relative"    VertSizing="relative"    Position="0 0"    Extent="1024 768"    MinExtent="320 320"    Visible="1">	    <GuiButtonCtrl        Name="AsteroidRestartButton"        Profile="BlueButtonProfile"        Text="Restart?"        ButtonType="PushButton"        canSaveDynamicFields="0"        isContainer="0"        HorizSizing="relative"        VertSizing="relative"        Position="48 36"        Extent="200 30"        MinExtent="100 15"        canSave="1"        Visible="1"        Active="1"        hovertime="1000"        groupNum="-1"        useMouseEvents="1" />			</GuiSpriteCtrl>

and it wouldn't work, it wouldn't add to the scene like it did in the GUI tutorial. Not to be discouraged i did some thinking and make a quick work around of making a real simple ingamegui.cs with a sprite being the button (i quickly used a nearby asset I.E the skull) and just // everything else so i had the code to look at for later

function createExitButton(){	%exitbutton = new Sprite(ExitButton);		%exitbutton.setBodyType( static );	%exitbutton.Position = "48 36";	%exitbutton.Size = "4 4";	%exitbutton.SceneLayer = 1;	%exitbutton.SceneGroup = 29;	%exitbutton.Image = "ToyAssets:TD_Bones_01Sprite";		myScene.add( %exitbutton );}

Setting the Scene Layer to 29 as i already had function InputManager::onTouchDown(%this, %touchId, %worldposition) Set for Clicking and Deleting of Asteroids so i simply added in a new command
//If this item belongs to SceneGroup 29, we exit    if(%myobj.getSceneGroup() == 29)	{	echo("Touched Exit Button");	MyModule.safedelete();	}

Back in the Main.CS
function MyModule::safedelete ( %this ){	echo("safedelete reached");	PlayerShip.safedelete();	Aster.safedelete();		MyModule.destroy();}function MyModule::destroy( %this ){		//destroyExitButton();	//destroyAsteroids(all);	//destroySpaceShip();	//destroyBackground();		shipcontrols.pop();	destroySceneWindow();	InputManager.safedelete();	MainMenu.Create();	ModuleDatabase.schedule(64, unloadGroup, "AsteroidStartGroup");}

Now for the serious Questions!!

First Question is was this way of creating a exit button (with the sprite and the commands) a good way of doing this? Or should those buttons all be made with an ingamegui that has the buttons spawn on the screen via TAML Files and that whole avenue of doing things? And can someone please just eye over the Destroy Function and possibly tell me any other commands i might need to put in? (either here or somewhere else) for instance i have these console dumps whenever i try to re Open the Asteroid Game
and when i try to ReClose the Game from the Quit Button, It Crashes (Console Logs at the end)

Second question is wether there are any good scoreboard tutorials available that would really assist me in creating a scoreboard for the two games? the Scoreboard Tutorial i found for Torque 2D is for the old version of torque 2D and since i am still struggling with understanding the GUI it makes it very hard to actually understand the tutorial to implement it into my games!!

My Last Question (For now, i obviously have other issues with Coding but i try my upmost to solve my problems before i bug the community) is wether there is much community support for Torque 2D? i want to keep my learning of the script going forward and hopefully try to create a few games and possibly even sell a game or two (Phone Marketplace Indie Development) but if i discover that the learning phase is too difficult as the community for Torque 2D no longer exists then i might make the change to some other program. I would really like to stay with torque as i have put all this groundwork in and i have had so much fun while doing what i have done up to this point!

Thanks for reading!! (what always seems to turn into a worddump whenever i type)

Code: Select all

Touched Exit Button   Entering myModule::safeDelete(myModule)      safedelete reached      modules/Asteroids/main.cs (58): Unable to find object: 'PlayerShip' attempting to call function 'safeDelete'      Entering myModule::destroy(myModule)         Entering destroySceneWindow()         Leaving destroySceneWindow() - return          modules/Asteroids/main.cs (75): Unknown command safeDelete.           Object InputManager(1199) InputManager -> ScriptObject -> BehaviorComponent -> DynamicConsoleMethodComponent -> SimComponent -> SimObject         Entering MainMenu::create(MainMenu)            SimObject::assignName() - Attempted to set object to name 'MenuDialog' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiSpriteCtrl' but a request to name it 'MenuDialog' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'AsteroidGameButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'AsteroidGameButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'FishGameButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'FishGameButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'QuitButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'QuitButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'OptionsDialog' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiSpriteCtrl' but a request to name it 'OptionsDialog' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'StartAsteroidGameButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'StartAsteroidGameButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'MainMenuButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'MainMenuButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'FishDialog' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiSpriteCtrl' but a request to name it 'FishDialog' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'StartFishGameButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'StartFishGameButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'MainMenuButton2' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'MainMenuButton2' was rejected.  This is typically because an object of that name already exists.         Leaving MainMenu::create() - return       Leaving myModule::destroy() - return    Leaving myModule::safeDelete() - return Leaving InputManager::onTouchDown() - return 1172 1197 Entering myModule::destroy(1165)   Entering destroySceneWindow()   Leaving destroySceneWindow() - return shipcontrols   modules/Asteroids/main.cs (75): Unknown command safeDelete.     Object InputManager(1199) InputManager -> ScriptObject -> BehaviorComponent -> DynamicConsoleMethodComponent -> SimComponent -> SimObject   Entering MainMenu::create(MainMenu)      SimObject::assignName() - Attempted to set object to name 'MenuDialog' but it is already assigned to another object.      Taml::parseElement() - Registered an instance of type 'GuiSpriteCtrl' but a request to name it 'MenuDialog' was rejected.  This is typically because an object of that name already exists.      SimObject::assignName() - Attempted to set object to name 'AsteroidGameButton' but it is already assigned to another object.      Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'AsteroidGameButton' was rejected.  This is typically because an object of that name already exists.      SimObject::assignName() - Attempted to set object to name 'FishGameButton' but it is already assigned to another object.      Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'FishGameButton' was rejected.  This is typically because an object of that name already exists.      SimObject::assignName() - Attempted to set object to name 'QuitButton' but it is already assigned to another object.      Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'QuitButton' was rejected.  This is typically because an object of that name already exists.      SimObject::assignName() - Attempted to set object to name 'OptionsDialog' but it is already assigned to another object.      Taml::parseElement() - Registered an instance of type 'GuiSpriteCtrl' but a request to name it 'OptionsDialog' was rejected.  This is typically because an object of that name already exists.      SimObject::assignName() - Attempted to set object to name 'StartAsteroidGameButton' but it is already assigned to another object.      Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'StartAsteroidGameButton' was rejected.  This is typically because an object of that name already exists.      SimObject::assignName() - Attempted to set object to name 'MainMenuButton' but it is already assigned to another object.      Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'MainMenuButton' was rejected.  This is typically because an object of that name already exists.      SimObject::assignName() - Attempted to set object to name 'FishDialog' but it is already assigned to another object.      Taml::parseElement() - Registered an instance of type 'GuiSpriteCtrl' but a request to name it 'FishDialog' was rejected.  This is typically because an object of that name already exists.      SimObject::assignName() - Attempted to set object to name 'StartFishGameButton' but it is already assigned to another object.      Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'StartFishGameButton' was rejected.  This is typically because an object of that name already exists.      SimObject::assignName() - Attempted to set object to name 'MainMenuButton2' but it is already assigned to another object.      Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'MainMenuButton2' was rejected.  This is typically because an object of that name already exists.   Leaving MainMenu::create() - return Leaving myModule::destroy() - return Module Manager: Cannot unload group 'AsteroidStartGroup' as it is not loaded.Entering toggleConsole(1)Leaving toggleConsole() - return Entering toggleConsole(0)Leaving toggleConsole() - return 0Entering toggleConsole(1)Leaving toggleConsole() - return Entering toggleConsole(0)Leaving toggleConsole() - return 0Entering AsteroidGameButton::onClick(1155)   Asset Manager: Failed to acquire asset Id 'ToyAssets:blueGradient' as it does not exist.Leaving AsteroidGameButton::onClick() - return Entering StartAsteroidGameButton::onClick(1160)   Executed C:/Users/Cameron Anderson/Desktop/GameCollection/modules/Asteroids/main.cs. Took 0 ms   Entering myModule::create(1228)      Executed C:/Users/Cameron Anderson/Desktop/GameCollection/modules/Asteroids/gui/guiProfiles.cs. Took 0 ms      Executed C:/Users/Cameron Anderson/Desktop/GameCollection/modules/Asteroids/scripts/scenewindow.cs. Took 0 ms      Executed C:/Users/Cameron Anderson/Desktop/GameCollection/modules/Asteroids/scripts/scene.cs. Took 0 ms      Executed C:/Users/Cameron Anderson/Desktop/GameCollection/modules/Asteroids/scripts/background.cs. Took 0 ms      Executed C:/Users/Cameron Anderson/Desktop/GameCollection/modules/Asteroids/scripts/spaceship.cs. Took 0 ms      Executed C:/Users/Cameron Anderson/Desktop/GameCollection/modules/Asteroids/scripts/asteroids.cs. Took 0 ms      Executed C:/Users/Cameron Anderson/Desktop/GameCollection/modules/Asteroids/scripts/controls.cs. Took 0 ms      Executed C:/Users/Cameron Anderson/Desktop/GameCollection/modules/Asteroids/scripts/ingamegui.cs. Took 0 ms      Executed C:/Users/Cameron Anderson/Desktop/GameCollection/modules/Asteroids/scripts/pausebehavior.cs. Took 0 ms      Entering createSceneWindow()      Leaving createSceneWindow() - return       Entering createScene()         Entering destroyScene()         Leaving destroyScene() - return       Leaving createScene() - return       Entering createBackground()      Leaving createBackground() - return       Entering createSpaceShip()      Leaving createSpaceShip() - return 0      Entering createAsteroids(20)      Leaving createAsteroids() - return       Entering createExitButton()      Leaving createExitButton() - return       Entering InputManager::Init_controls(InputManager)      Leaving InputManager::Init_controls() - return    Leaving myModule::create() - return Leaving StartAsteroidGameButton::onClick() - return Entering PlayerShip::onCollision(1235, 1238, 0 0 -1.0000 0.0000 -1.8538 -0.4744 336.9832 -12.6657)   PlayerShip Defeated and Deleted!   Entering myModule::Lose(myModule)      modules/Asteroids/main.cs (41): Unable to instantiate non-conobject class ImageFont.      modules/Asteroids/main.cs (49): Unable to find object: 'mainScene' attempting to call function 'add'      modules/Asteroids/main.cs (50): Unable to find function printMessage      modules/Asteroids/main.cs (51): Unable to find object: '' attempting to call function 'sayHello'   Leaving myModule::Lose() - return Leaving PlayerShip::onCollision() - return Entering InputManager::onTouchDown(1258, 0, 48.5359 35.5851)   0   Touched Exit Button   Entering myModule::safeDelete(myModule)      safedelete reached      modules/Asteroids/main.cs (58): Unable to find object: 'PlayerShip' attempting to call function 'safeDelete'      Entering myModule::destroy(myModule)         Entering destroySceneWindow()         Leaving destroySceneWindow() - return          modules/Asteroids/main.cs (75): Unknown command safeDelete.           Object InputManager(1258) InputManager -> ScriptObject -> BehaviorComponent -> DynamicConsoleMethodComponent -> SimComponent -> SimObject         Entering MainMenu::create(MainMenu)            SimObject::assignName() - Attempted to set object to name 'MenuDialog' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiSpriteCtrl' but a request to name it 'MenuDialog' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'AsteroidGameButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'AsteroidGameButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'FishGameButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'FishGameButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'QuitButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'QuitButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'OptionsDialog' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiSpriteCtrl' but a request to name it 'OptionsDialog' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'StartAsteroidGameButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'StartAsteroidGameButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'MainMenuButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'MainMenuButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'FishDialog' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiSpriteCtrl' but a request to name it 'FishDialog' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'StartFishGameButton' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'StartFishGameButton' was rejected.  This is typically because an object of that name already exists.            SimObject::assignName() - Attempted to set object to name 'MainMenuButton2' but it is already assigned to another object.            Taml::parseElement() - Registered an instance of type 'GuiButtonCtrl' but a request to name it 'MainMenuButton2' was rejected.  This is typically because an object of that name already exists.         Leaving MainMenu::create() - return       Leaving myModule::destroy() - return    Leaving myModule::safeDelete() - return

#### Re: Newbie Questions

LukasPJ
Posts: 361
Joined: Tue Feb 03, 2015 7:25 pm

Welcome to the forums! I edited your post and added code - highlight, that often increases the likelihood that you get a response.

I'm not able to look at it myself, atm, so good luck and I hope you have a good experience with T2D ☺️