");//s"> NextToken does not work as expected with tabs | Torque Game Engine | Forums | Community | GarageGames.com

Game Development Community

NextToken does not work as expected with tabs

by Ritchey "Hawk" Mulhollem · in Torque Game Engine · 09/14/2004 (7:08 pm) · 1 replies

I am having a problem with nextToken seeing "\t" as "\t\t" and there by skipping variables which should be set to NULL.

Consider this:

%loop=1;//required because nextToken nulls %line
   while(%loop){
      %line=nextToken(%line,data,">");//split on this
      %data=nextToken(%data,servername,"\t");
      %data=nextToken(%data,users,"\t");
      %data=nextToken(%data,max,"\t");
      %data=nextToken(%data,public,"\t");
      %data=nextToken(%data,ip,"\t");
      %data=nextToken(%data,port,"\t");
      %data=nextToken(%data,worldfile,"\t");
      %data=nextToken(%data,uptime,"\t");
      %data=nextToken(%data,status,"\t");
      WorldList.addRow(%i, %servername TAB %users@"/"@%max TAB %uptime TAB %public TAB %ip@":"@%port TAB %file);%i++;
      if(%line $=""){%loop=0;}
   }

If my input data looks like this:

Strong Hold^^64^Public^10.1.1.101^28000^ft3d/data/missions/stronghold.mis^STARTING UP^Starting>

Because nextToken sees "^^" as "^" variable "users" never gets set to NULL!

What torque script really needs is a split function! That way we can turn that entire ugly mess into one simple line of:

(servername,users,max,public,ip,port,worldfile,uptime,status)=split("\t",%line);

Isn't that a much better way? We cut to the chase instead of playing around chokin' the token!

#1
09/14/2004 (10:31 pm)
That "simple" example would introduce a whoooole lot of funky stuff to the script language... But I agree, it's a really snazzy syntax.

I think there's a way to get the Nth element from a string. getWord. Maybe there's a token-like variant.