Game Development Community

Problem linking function to gui button

by __._ · in Torque Game Engine · 10/05/2006 (4:02 am) · 14 replies

A new day, a new problem :)

Based on the getting started guide, I've created a simple menu with a button that calls a function to load a mission. However, it only works if I use the exact names from the getting started guide. If I change the command of the button to e.g. "startGame();", and modify the function name inside main.cs to "startGame()" as well, nothing happens. The function isn't called. If I create a new function "Test()", have it echo "test" to the console, and attach this to the command of the button, nothing either. If I write echo("test"); in the command field directly it works though. If I change "startGame" back to "loadMyMission" it works again also..

Am I forgetting something? It's not a matter of executing a file I forgot, as all I did was change the name of a function in two places. Any ideas?

Thanks

#1
10/05/2006 (5:25 am)
Is there an error being produced in the log when you press this button? If so, what does it say?
#2
10/05/2006 (5:37 am)
Try deleting DSO's.
#3
10/05/2006 (5:44 am)
Tried that before posting :)
No error, in fact, totally nothing happens when I click the button. As if there is no command specified..

If I scroll WAY up in the log, i see

Quote:
exec: Warning! Found a DSO from the future! (FDG/main.cs.dso)

But I get regardles of wether I deleted it or not. FDG/main.cs is the file that contains the buttons function.
#4
10/05/2006 (6:54 am)
Quote:
Quote:

--------------------------------------------------------------------------------

exec: Warning! Found a DSO from the future! (FDG/main.cs.dso)

--------------------------------------------------------------------------------


This is a daft warning, it is telling you that it is going to recompile the CS file. Nothing there to worry about.

Can you post the GUI code for the button, and the function declaration from the main.cs file?
#5
10/05/2006 (8:51 am)
Here it is =)

function startGame()
{
   // make sure we are not connected to a server already
   disconnect();

   // Create the server and load the mission
   createServer("SinglePlayer", expandFilename("./data/missions/mission1.mis"));

   // Make a local connection
   %conn = new GameConnection(ServerConnection);
   RootGroup.add(ServerConnection);
   %conn.setConnectArgs("Player");
   %conn.setJoinPassword("None");
   %conn.connectLocal();
}
This basically was the loadMyMission function, just renamed it.

new GuiButtonCtrl() {
      Profile = "GuiButtonProfile";
      HorizSizing = "right";
      VertSizing = "bottom";
      position = "65 99";
      Extent = "140 30";
      MinExtent = "8 2";
      Visible = "1";
      Command = "startGame();";
      text = "Start a new game";
      groupNum = "-1";
      buttonType = "PushButton";
   };
And this is my very simple button.
#6
10/05/2006 (9:11 am)
Well, not sure what to say. I copied your code above into my TGE and except for one change, it worked as you wanted it to work. The only change I did was to change ./data/missions/mission1.mis to just ~/data/missions/stronghold.mis. Also note the change from a period infront of the data to ~. Regarless the function was called as expected.
#7
10/05/2006 (10:13 am)
Well not sure the ~ can be the problem (going to try ofcourse) because my function isn't even called. If I put an echo in it, nothing shows up in the console.. But if I remove the dso and restart, it compiles a new one, but still gives the message exec: Warning! Found a DSO from the future! (FDG/main.cs.dso).
#8
10/05/2006 (10:36 am)
I'll betcha five bucks the problem here is the DSO from the future.

delete the DSO, and make sure it's deleted.

then run the app again,
and make sure the .dso is re-created.

Quote:This is a daft warning, it is telling you that it is going to recompile the CS file.
- are you sure about that simon ? i would have expected it to issue the warning and then use the compiled .dso from the future, not recompile.
#9
10/05/2006 (11:47 am)
@Orion

Yes, I am sure. If you edit the cs file, the datetime stamp is changed to the current datetime stamp. So how can there be a dso from the future? It should be a dso from the past as it has an older datetime stamp or a cs from the future. Not saying the warning is invalid, just daft.

// Let's do a sanity check to complain about DSOs in the future.
   if(compiled && rCom && rScr && Platform::compareFileTimes(comModifyTime, scrModifyTime) < 0)
   {
      Con::warnf("exec: Warning! Found a DSO from the future! (%s)", nameBuffer);
   }

comModifyTime is the DSO modified time
scrModifyTime is the CS modified time

This is the condition it is looking for compiled == true && rCom != NULL && rSrc != NULL && compairFileTimes < 0

The only way compairFileTimes can be < 0 is as follows

compareFileTimes(const FileTime &a, const FileTime &b)
{
   if(a.v2 > b.v2)
      return 1;
   if(a.v2 < b.v2)
      return -1;
   if(a.v1 > b.v1)
      return 1;
   if(a.v1 < b.v1)
      return -1;
   return 0;

So, -1 is only returned when

a < b which is
comModifyTime < scrModifyTime which is
DSO DateTime < CS DateTime.
Older < Newer
Past < Future


I changed mine as below so it made more sence to me.

exec: Warning! Found a DSO from the past!

Now it maybe that GG indended it to report future DSO, then it should read

Platform::compareFileTimes(comModifyTime, scrModifyTime) [b]>[/b] 0

instead.

@RJ

Didn't think the ~ was the fix, but the point is, I copied your code into my application and it worked with only that one change. At first I put an echo statement in the function just to make sure it was called, then I added the rest.

Take a clean install of TGE and add your button to the mainMenu.gui then add a fuction that echos text. This way, you remove any other changes done that might mess things up. I just did what I suggested in 30 seconds to make sure it works. if that does not work for you, then I am not sure what else to tell you.
#10
10/06/2006 (1:17 am)
Ok I removed every single DSO file I could find, restarted the engine, and... still nothing. Then if I open the GUI editor, check things (chancged nothing) and go back out of it, the console give:

exec: Warning! Found a DSO from the future! (creator/ui/prefs.cs.dso)

but only after I pressed F10 and left the editor again. It doesn't mention the main.cs.dso file now, but still nothing happens when I click the button.

Removing the button and creating a new one (compiling dso's in between) didn't help either. Do I really have to start all over again? Because that would be the 2nd time even though I did nothing weird...

Edit: could it pherhaps be related to my start-up sequence? I have constructed my own logo fade-in just to practise (and I couldn't find where starter.fps directed the logo fade to it's main menu) so my project starts with "startupGui", not "mainMenuGui", and the following code makes it tick:

schedule(100, 0, checkStartupDone );

function StartupGui::click()
{
	StartupGui.done = true;
	checkStartupDone();
}

function checkStartupDone()
{
	if (StartupGui.done)
		Canvas.setContent(MainMenuGui);
	else
		schedule(100, 0, checkStartupDone );
}

Still.. it's odd that it works when I name the function "loadMyMission" as in the getting started, and not if I change the name. Sounds like your typical cached memory somewhere but I removed them all more then once...
#11
10/06/2006 (2:48 am)
I tried making a new menu. New name, new files. everything new. It doesn't help one bit. If I make the command field anything but "loadMyMission()" it simply doesnt do anything. If I make it loadMyMission it gives me "cant find function" which is normal ofcourse, but why oh why won't it do the same if I specify a different function name? I used search and deleted every single dso file on my hdd, and as said even made all new files so what on earth is the problem?

When I change tutorial.base's main menu and add a button with "startgame()" it correctly claims it cannot find the function. But after making yet again a copy of the tutorial.base, renaming it to the same folder as before, the same stuff happens all over again: give a button any command calling a function other then loadMyMission and it stops working. However I did find out, that if I make the command field into: 'echo("test"); startGame();', the console does show "test", simply ignoring the function.
#12
10/06/2006 (3:48 am)
The problem seems solved, but I'd still like to hear an experts opinion about it :) Could it have been pure coincidence that I gave my function the name of a functon that already exists by default somewhere in Torque? Or a reserved name or something. I changed "startGame" to "startTheGame" and it seems to be working ok now. Silly that I didnt think about this earlier.
#13
10/06/2006 (5:12 am)
There is one startGame in tutorial.base, its in common/server/game.cs. But it was loaded early at boot, and should of been overloaded by your function of startGame. This would of caused major issues as the mission tried to load, which would result in lots of errors in the log. Still, you would of seen log entries as it started to process.



Humm, unless you changed things around so that

// Load up common script base
loadDir("common");

was after

exec("./client/ui/mainMenuGui.gui");

somehow, then you the common version of startGame would of overloaded yours and the common version is empty, so it would do nothing.


Well, glad you figured it out and got it running. I was too focused on trying to get the button to run the command, I never thought about looking to see if the command was overloaded.
#14
10/06/2006 (6:22 am)
Well didn't switch them, but oh well... some things are meant to remain a secret ;) Not sure this is one of them though.