Game Development Community

Returns to early

by Matthew Grint · in Torque Game Engine · 09/16/2005 (12:30 pm) · 2 replies

Hi,
This question probably has a very simple answer that my feeble programming cannot find, but I am really stuck on this. I have a function which attempts to find the model to use as the PlayerBody - but I cannot get it to return the correct data. The programming I have done is fairly shoddy, as i'm sure you will all see. What's happening is the function calls getPlayerBody and it returns 'null' before the second function (OnLine) has processed the data and given a reply, how can I get this to return the data ($Race) I want?

function getPlayerBody(%name){
   %action = "getbody";
   %client.authReturned = false;
	%query 			= "user="@%name@"\t"@
				        "action="@%action@"\r";
	%server 		= $AuthServer;
	%path 			= $AuthServerPath;
	%script 		= %path @ "game_login.php";
	%upd = new HTTPObject(GetBody);
	%client.sendObject = %upd;		//store object details just in case
	%upd.clientid = %client;
	%upd.get(%server, %script, %query);
   return($Race);
   }
}

function GetBody::onLine( %this, %line )
{
	if(StrStr(%line, "GlowyBody") != -1)
	{
      $Race = "GlowyBody";
		
	}
   if(StrStr(%line, "OrcBody") != -1)
	{
      $Race = "OrcBody";
		return($Race);
	}
   else
   {
      $Race = "GlowyBody";
   }
  return($Race);
}

Thanks for any help, I really appreciate it!

Matthew Grint

[Update: Apologies for the typo in the Topic, and any others that may be in here]

#1
09/17/2005 (5:49 pm)
OnLine is called asynchronously. Torque finishes executing one block before it executes other stuff; you have to actually wait for onLine in your code, rather than just returning right off.

It's kinda lame to do this, but it's a lot better then having your code hang forever because the webserver is feeling slow. ;)
#2
09/18/2005 (1:54 am)
Ah thanks, I kinda bodged it into the login code to try and speed things up a bit and it seems to be working now.

Thanks for your help and great work on TGE!