Game Development Community

Wierd issue (GUI button)

by Andrei Georgescu · in Torque Game Builder · 07/28/2010 (11:19 am) · 2 replies

Hi! This is my first post, so great to meet you all!

I have a simple issue. I used search and tried different solutions but nothing seems to work.

Well, when my player's life reaches 0 I pause game and then bring 2 buttons (restart / quit) and a textbox ("you lose"). The problem is that I've tried in lot ways to call a function when a button is pressed but nothing worked. I tried both to create the button in script and in GUI editor and setting it invisible. Nothing works. Following the most posts on the forums I am getting "parse error" in console.

If I create the button from script I don't see it.. Why? :(
function initRestart()
{
   txtLose.Visible = 1;
   //cmdRestart.Visible = 1;
   new GuiButtonCtrl(cmdRestart)  
   {        
      class = "btnRestart";
      canSaveDynamicFields = "1";
      parent = "mainScreenGui";
      profile = "GuiButtonProfile";        
      horizSizing = "right";        
      vertSizing = "bottom";        
      position = "330 270";        
      extent = "140 30";        
      minExtent = "8 2";        
      visible = "1";      
      canSave = "1";  
      command = "btnRestart.mainRestart();";        
      text = "Restart";        
      groupNum = "-1";        
      buttonType = "PushButton";        
   };  
   cmdQuit.Visible = 1;
}

#1
07/28/2010 (5:33 pm)
In script, I thought you had to manually call "mainScreenGui.add( cmdRestart );".

Also, as for the "parse error", that usually means that your command is invalid. Make sure you have an object called "btnRestart" and a function called "function btnRestart::mainRestart( %this )".
#2
07/29/2010 (10:24 am)
OMG all I had to do is to add "%this" in brackets. Thanks a lot! Funny..