Author Topic: Help with looping issues [SOLVED]  (Read 746 times)

So, i was just building around a castle and while i'm building. I always type the command ./brickcount to look for
the amount of bricks spent (i don't like wasting memory). Then i though of creating a script to give me support:

Code: [Select]
function serverCmdshowBricks(%this, %asw)
{
  %flag = false;
  //Let's toggle if
  if(%asw $= "on")
  {
    %flag = true;
  } else if(%asw $= "off") %flag = false;
  
  while(%flag) //Yes... .-.
    %this.bottomPrint("The number of bricks is: " @ getBrickCount(), 0);
}


This first code didn't work. When i type "./showBricks on" it gives an error : "Error runtime blablabla cancer blabla"

Code: [Select]
function serverCmdshowBricks(%this, %asw)
{
  %flag = false;
  //Let's toggle if
  if(%asw $= "on")
  {
    %flag = true;
  } else if(%asw $= "off") %flag = false;
  
  for(;%flag;) //Why not? It works at C :-(
  {
    %this.bottomPrint("The number of bricks is: " @ getBrickCount(), 0);
  }
}
This was my second try and nothing .-.

Any idea?

« Last Edit: March 10, 2016, 05:38:09 PM by FelipeO_O »

Blockland hates infinite loops, and stuffs itself whenever you use them.
Use schedule to create a delayed loop.

function scheduledLoop(%bool) {
    if(isEventPending($scheduledLoop)) {
        cancel($scheduledLoop);
    }
    if(!%bool) {
        return;
    }
    // code here
    $scheduleLoop = schedule(100, 0, scheduledLoop, %bool);
}


Schedule's arguments are (delayInMS, referenceObject, functionName, arg0, ...).
This will repeat the function scheduledLoop every 100ms, or 1/10th of a second.
scheduledLoop(true); will start it, and scheduledLoop(false); will stop it.

I'm a bit confused by this...why not set a keybind to call the getBrickCount(); command?

Blockland hates infinite loops, and stuffs itself whenever you use them.

Yes, it's boring when you have a limited engine.
Anyway, thank you so much!

I'm a bit confused by this...why not set a keybind to call the getBrickCount(); command?

I don't think that is efficient