Author Topic: looping bottomprint  (Read 1213 times)

so i'm creating a gamemode where several variables will be monitored constantly and bottomprinted. (the variables are also different for each client)
now if i just make a loop in my gamemode's server.cs, then it won't ever interpret any other lines of my script, correct? so how can i work around this? should i make a separate server.cs that constantly bottomprints some global vars? would that work?

What? You aren't making sense.

Use a schedule to loop it instead of just a while(true) loop.

Code: [Select]
function loopToAll() {
    for(%clientidx  = 0; %clientidx < clientGroup.getCount(); %clientidx++) {
        %client=clientGroup.getObject(%clientidx);
        %client.bottomPrint("Health: " @ %client.player.getDamagePercent() @ "% Weapon: " @ isObject(%wep=%client.player.getMountedImage(0))?%wep.getName():"None", 5);
    }
    schedule(4500, 0, loopToAll);
}
« Last Edit: August 10, 2013, 07:16:21 PM by $trinick »

What? You aren't making sense.
elm, my feeble mind can't comprehend how torque reads scripts
but i realize now schedules do what i need
Use a schedule to loop it instead of just a while(true) loop.

Code: [Select]
function loopToAll() {
    for(%clientidx  = 0; %clientidx < clientGroup.getCount(); %clientidx++) {
        %client=clientGroup.getObject(%clientidx);
        %client.bottomPrint("Health: " @ %client.player.getDamagePercent() @ "% Weapon: " @ isObject(%wep=%client.player.getMountedImage(0))?%wep.getName():"None", 5);
    }
    schedule(4500, 0, loopToAll);
}

exactly what i needed. thanks

Also, a word of advice, as general practice a while(true) loop is never a good thing in Torque Script.

Even if I'm confident that I will properly exit the loop at some point with a break, I still do something like for(%i=0;%i<10000;%i++) just as protection that in case something isn't exactly right I won't just crash Blockland.

right. should i cancel the schedule at the beginning of the loop? a friend of mine has advised that before when dealing with schedule loops, to avoid a backlog or something

right. should i cancel the schedule at the beginning of the loop? a friend of mine has advised that before when dealing with schedule loops, to avoid a backlog or something
Yes, it's generally a good idea to cancel the schedule at the start of the loop. It shouldn't be, but Torque's pretty stuffty and I often forget it needs a bit of finessing to control in the way you want.