Author Topic: How can I list a set of information in a text list with a loop?  (Read 561 times)

Suppose you have a database full of information.  You connect to it with PHP, and you grab the information.

Is there some way that you can make an array (such as an array of %name, %file, %img, %link) that constantly grabs what information is in the database, ++s itself, then grabs the next set of data in a database and so on until it finds there is none and terminates itself?

Think of how, when you're at the Blockland sever join screen, you can click "Query Internet" to make a list of servers appear.  How does this work? How does Blockland get server information from whatever PHP file it connects to, store it, then make a dynamic list full of information? How does it store and pull information such as the server name, IPv4 address, player count, etc. for long enough to load it into the list?

master2.blockland.us

the query tcp gets the html webpage and then parses it, each line found creates an object with the correct vars from the line and puts them into a group, found by this function
function ServerInfoSO_Add(%ip, %pass, %ded, %name, %currPlayers, %maxPlayers, %mods, %map, %brickCount, %demoPlayers)
{
   if ($ServerSO_Count <= 0)
      $ServerSO_Count = 0;

new ScriptObject(ServerSO){
      ping = "???";
      ip = %ip;
      pass = %pass;
      ded = %ded;
      name = %name;
      currPlayers = %currPlayers;
      maxPlayers = %maxPlayers;
      mods = %mods;
      map = %map;
      brickCount = %brickCount;
      demoPlayers = %demoPlayers;
      id = $ServerSO_Count;
   };
   $ServerSO[$ServerSO_Count] = 0;
   if (!isObject("ServerInfoGroup"))
   {
      new SimGroup("ServerInfoGroup"){
      };
      RootGroup.add("ServerInfoGroup");
   }
   ServerInfoGroup.add($ServerSO[$ServerSO_Count]);
   %strIP = %ip;
   %strIP = strreplace(%strIP, ".", "_");
   %strIP = strreplace(%strIP, ":", "X");
   $ServerSOFromIP[%strIP] = $ServerSO_Count;
   $ServerSO_Count++;
}


after the objects are done being added it will then send a command to add stuff to a text list control (which is how it displays your servers)



there are 3 methods of creating 'arrays' - each depends on what you are planning to do with them
- create a text list control and add rows to them
- create a scriptgroup and add a script object for new objects (not recommended)
- create a list of global vars and use them any time (best option for this case)



global vars are the easiest one, if you want to erase global variables based on their name, use: deleteVariables("$varName*"); which will delete all variables starting with "$varName"

example of creating an array of global variables
for(%i = 1; %i <= 10; %i++) {
    $Client::Stuff[$Client::Stuff++] = "line " @ %i;
}


10 times, it will make $Client::Stuff1, $Client::Stuff2, $Client::Stuff3, and so on until the loop stops, this also increases the var $Client::Stuff, which the value should be 10

if you run this more than once without setting the $Client::Stuff back to 0, it'll start from where it was and will repeat the same process
« Last Edit: May 31, 2017, 09:54:54 PM by Kyuande »


-snip-


So I just need to connect to my site with Greek's TCP function, make a function that creates rows for each result (I guess you do it with a for loop like you did with making an array with the information inserted), then display it as a row?

So I just need to connect to my site with Greek's TCP function, make a function that creates rows for each result (I guess you do it with a for loop like you did with making an array with the information inserted), then display it as a row?

yeah, use objectClassName::onLine(%obj, %line), make sure you do some checks when the thing "START" and "END" (etc) or you might get weird results