SRL Archive - The Bashing Club / BBQ Pit

loops...


footballjds

2012-11-26 16:09:06

tl;dr
Place a wait(10) or greater inside EVERY loop in which you're waiting for something to happen/change.


this is to everyone out there. Please put some waits in your loops that WAIT for something!!!!

IE.

repeat
blah blah
until FindThis;

you're waiting for something in that loop so you should be waiting!!! wait at least 10-50 ms…

If you're waiting for your inv count to change use a wait in the loop!!! if you're checking something and you have no wait you'll use 100% of the processor! it looks like lag but really it POOR coding….

pretty much, the ONLY loop that doesn't require a wait is a for loop that's going through an array…(there's other exceptions, but as a rule of thumb, if you're waiting for something use a wait in your loop or else it'l devour people's processors)

EDIT:
Just an FYI, I see this poor coding habit in srl members scripts just as often as jr's and below. This isn't really a rage thread as much as a notice to all programmers. However i do kinda rage when I see my char freeze for 4 seconds because of a loop with no wait. For scripters, if your CPU is more powerful the lag will be less/minimal but if someone's computer is simply mediocre they'll suffer more.

Footy

2012-11-26 16:14:00

From: footballjds
tl;dr
Place a wait(10) or greater inside EVERY loop in which you're waiting for something to happen/change.

this is to everyone out there. Please put some waits in your loops that WAIT for something!!!!

IE.

repeat
blah blah
until FindThis;

you're waiting for something in that loop so you should be waiting!!! wait at least 10-50 ms…

If you're waiting for your inv count to change use a wait in the loop!!! if you're checking something and you have no wait you'll use 100% of the processor! it looks like lag but really it POOR coding….

pretty much, the ONLY loop that doesn't require a wait is a for loop that's going through an array…(there's other exceptions, but as a rule of thumb, if you're waiting for something use a wait in your loop or else it'l devour people's processors)


Thank you, a lot of people required this notice.

Why shoudn't we have wait's while sifting through arrays? Even a small Wait(5) to give our CPU a small break?

litoris

2012-11-26 16:18:15

It's kind of common sense if the coder is actually thinking about what they are doing.

footballjds

2012-11-26 16:20:31

From: Footy
Thank you, a lot of people required this notice.

Why shoudn't we have wait's while sifting through arrays? Even a small Wait(5) to give our CPU a small break?


Because you don't want to wait. You want to go through the array as fast as possible. For instance, when going through TPA's you don't want it to take more then say 16 or 32 ms. if your for loop through an array takes longer then this you should try to speed it up.

Rezozo

2012-11-26 17:13:33

Or you could just do repeat-until(something) with nothing in the repeat until :p This would make it literally repeat nothing till something is found :D
~Rez

masterBB

2012-11-26 17:19:01

From: Rezozo
Or you could just do repeat-until(something) with nothing in the repeat until :p This would make it literally repeat nothing till something is found :D
~Rez


His point is that should put a wait inside there. Otherwise it will spam you CPU with that searchfunction, which might hurt your CPU his feelings.

footballjds

2012-11-26 17:25:33

From: Rezozo
Or you could just do repeat-until(something) with nothing in the repeat until :p This would make it literally repeat nothing till something is found :D
~Rez


try doing that rezozo, tell me what your resource manager reports about your CPU. Then add a wait(15); and see the difference ;)

From: litoris
It's kind of common sense if the coder is actually thinking about what they are doing.


I agree it's common sense. However, there's a plethora of awesome scripts (where the coder obviously knows what they're doing) and this mistake is still made.

mounty

2012-11-26 17:48:36

A good point I would say. For most of thing I go longer than that for my waits so that the loop isn't going through pointless cycles.