why no while commands?
elementalelf
2007-09-07 21:57:30
ive looked through as many srl scripts as i can without going insane, and im yet to see a while command.
these are probably one of the better loop commands, and nobody uses them anymore.
is there something im missing/dont know?
Starblaster100
2007-09-07 22:11:06
Nope, i use while do commands. Its just the techniques you prefer really.
R0b0t1
2007-09-07 22:35:57
repeat;
until();
I like that more than while, but I use both. For loops count, so they are popular.
The Claw
2007-09-07 22:58:06
I use them a fair bit
pwnaz0r
2007-09-07 23:11:02
i use While Flag do aloot
Bobarkinator
2007-09-07 23:42:38
I use them occasionally but most people use repeat until();
SKy Scripter
2007-09-08 00:28:01
i use While alot…
mostly for arrays…
btw this function works faster then the "rearrangetpa", even when "rearrangetpa" is in SCAR, lmfao
procedure BubblePoints(var P : TPointArray);
var
sl, n, i, l : Integer;
C : TPoint;
begin
l := Length(P);
sl := l - 1;
while (n < l) do
begin
if (p[sl].x <= p[i].x) and (p[sl].y <= P[i].y) then
begin
C := P[sl];
P[sl] := P[i];
P[i] := C;
end;
sl := sl - 1;
inc(n);
end;
end;
Special Ed
2007-09-08 01:27:50
W00t? I use while a lot in my scripts its just not always effective or as justifiable in as many places as a simple repeat statement, so not a lot of people use them frequently.
n3ss3s
2007-09-08 02:03:02
Only reason I dont use while is so much that the
"while () do
begin" looks ugly and it has no "tags" like Repeat- Until which you can use without begin and end
Santa_Clause
2007-09-08 03:43:56
I prefer For/To/Do loops :p
n3ss3s
2007-09-08 04:01:46
for to do and repeat until rule
Santa_Clause
2007-09-08 04:39:35
procedure TypeStringUntilMetNumber;
var
i : integer;
begin
for i := 1 to 10 do
TypeSend('SRL Forums Rule');
end;
procedure TypeStringUntilMetInteger;
var
i : integer;
begin
repeat
TypeSend('SRL Forums Rule');
i := i + 1;
until(i = 10);
end;
For/To/Do is shorter by 2 lines, which is alot compared to a 7 line procedure.
The Claw
2007-09-08 04:49:47
But look i made it in "while to do" in just 1 line:
procedure zzzzz; var i: integer; begin while i <= 10 do begin Writeln('SRL Forums Rule'); i := i + 1; end; end;
Santa_Clause
2007-09-08 04:53:09
How about we keep a maximum of one semi-colon on each line ;)
~alex~
2007-09-08 07:26:38
I prefer whiles over repeats tbh. Makes more sense when reading it.
Santa_Clause
2007-09-08 07:51:55
Whiles of repeats?
Sumilion
2007-09-08 08:46:11
Think he means over,
I use em both. Whatever comes to mind first.
nielsie95
2007-09-08 10:48:19
From: SKy Scripter
i use While alot…
mostly for arrays…
btw this function works faster then the "rearrangetpa", even when "rearrangetpa" is in SCAR, lmfao
procedure BubblePoints(var P : TPointArray);
var
sl, n, i, l : Integer;
C : TPoint;
begin
l := Length(P);
sl := l - 1;
while (n < l) do
begin
if (p[sl].x <= p[i].x) and (p[sl].y <= P[i].y) then
begin
C := P[sl];
P[sl] := P[i];
P[i] := C;
end;
sl := sl - 1;
inc(n);
end;
end;
That doesn't give the same effect as ReArrangeTPA?
Starblaster100
2007-09-08 12:23:11
You know there are specific reasons for using "for to do", "repeat until" and "while do"
Its technique, and you could get marked down in SRL SC for using the "wrong" one. (I say wrong one, but really there is no wrong answer. Its just the situation you are in)
n3ss3s
2007-09-08 12:26:44
Its technique, and you could get marked down in SRL SC for using the "wrong" one. (I say wrong one, but really there is no wrong answer. Its just the situation you are in)
for loop when you know the amount of repeating, while and repeat when you want to get your chars "hanging" xD
Infantry001
2007-09-08 13:56:28
I think its really what you prefer. For to do loops are better for timed loops/counters. While and repeat are better for repetitive actions.
SKy Scripter
2007-09-08 15:45:16
From: nielsie95
That doesn't give the same effect as ReArrangeTPA?
lol, well i tested it and it orderd my points from least to greatest..
but then i changed a few points… and lol it didnt work… -.- what i was trying to do was make it order fast as possible… i guess it cant be done in one repeat. :(
R0b0t1
2007-09-08 17:16:11
If you've ever used a C language or Java, repeat loops are the same as "do while", as they both check the condition after execution.
Wrong one? I hope you mean using a while loop for a counting thing instead of a for loop, because while and repeats are almost the same. (Well, thinking about it, I can see the point, but very few cases.)
What does TBH mean?
Starblaster100
2007-09-08 17:35:53
TBH = To be honest Urbandictionary.com :)
"While do" loops first check if the statement is true before carrying out the functions in them. if the statement isn't true, nothing will be carried out.
Repeat until will always do the functions at least once as it checks if the desired thing is true at the end of the loop
For to do are usually used for timeouts, and when you know the exact amount of times you want to carry out a function.
Obviously all of these have exceptions, they are just the general ideas
Wanted
2007-09-08 18:26:44
From: Starblaster100
"While do" loops first check if the statement is true before carrying out the functions in them. if the statement isn't true, nothing will be carried out.
Repeat until will always do the functions at least once as it checks if the desired thing is true at the end of the loop
This is the only difference between 'while do' vs. 'repeat until' that I have ever noticed.
Starblaster100
2007-09-08 18:48:50
Thats the only difference you will even notice as thats the only difference between them ;)
Wanted
2007-09-08 18:53:09
From: Starblaster100
Thats the only difference you will even notice as thats the only difference between them ;)
Yea, lol, you can tell I waste to much time worried about standards and finding out the differences between certain techniques and styles. It never fails to amaze me when I find out that some times they have a
major or even
minor difference…
Starblaster100
2007-09-08 19:03:05
From: Icefire908
Yea, lol, you can tell I waste to much time worried about standards and finding out the differences between certain techniques and styles. It never fails to amaze me when I find out that some times they have a major or even minor difference…
Thats the beauty of the techniques and procedures.
Its like Wait and Sleep. Lots of people don't know the differences between the two of those, and sometimes the effects can be quite major.
R0b0t1
2007-09-08 19:49:11
I'm interested, master. Please tell me the difference 'o great master.
Wanted
2007-09-08 20:31:09
From: r0b0t1
I'm interested, master. Please tell me the difference 'o great master.
True knowledge is gained by searching.
in other words
:google:
:f:
The Claw
2007-09-08 20:40:19
Waiting is staying awake until you get the phone call, while sleeping is going to sleep and letting the phone call wake you up
R0b0t1
2007-09-08 21:26:18
But that would mean both are the same, as SCAR needs to created the phone to wake you up.
Before you post: If you are right, calling Wait() would start counting "ticks" on the local thread, and calling Sleep() would stop all processes on the thread completely. That would mean the program would end.
Or is SCAR multi-thread?
EDIT: The SCAR manual says that Sleep() is an alias for Wait()
EDIT: What are the consequences when using sleep instead of wait?
warship45
2007-09-09 05:55:32
most people will used repeat until because the code needs to be run at least once and will be run at least once. i never really use while loops unless i have a variable that will change and i don't what the loop to run at all when it is at a certain value. And you are right u can use both of them for most things but it is better to think of it does it need to run once or does it not like what was said in one of the post above
shaunthasheep
2007-09-09 08:24:55
Mostly for waiting on something is when I use them.
while (LoadingColorsOnMainScreen)
Wait(100);
Infantry001
2007-09-09 12:45:54
Well, i would like to know more about the difference between Wait and Sleep.
Starblaster100
2007-09-10 04:33:25
o sorry, didn't see this thread.
From: Starblaster100
There is a subtle difference.
Wait uses the Process command. When you load a ton of Procedures into a SCAR loop, it will not execute them until it comes across a process command (which is in "wait") Thats why we always have tiny waits in our scripts, so SCAR can process everything we tell it to do and not lag like hell.
Sleep doesn't have this process command. It just simply waits or "puts the application to sleep" for a certain amount of time you set.
From: markus
So instead of tiny waits, why don't do GetApplication.Processmessages?
From: Starblaster100
Thats basically what Wait is. but sometimes we need to do more GetApplication.Processmessages then normal, depending on the resources our procedures take up. Wait is just a nice little procedure to do that for us so as we dont have
[php]
ClickMouse(x, y, True);
GetApplication.Processmessage
GetApplication.Processmessage
GetApplication.Processmessage
GetApplication.Processmessage
GetApplication.Processmessage
GetApplication.Processmessage
GetApplication.Processmessage
GetApplication.Processmessage
ClickMouse(x, y, False);
[/php]
everywhere :p
And also…
From: Cheesehunk
Sleep contains 1 extra letter, waste of valuable time..:rolleyes:
Santa_Clause
2007-09-10 04:38:42
I just love what Cheesehunk said :p
So…why would anyone use sleep if they have Wait?
Starblaster100
2007-09-10 04:47:25
A good question… sometimes you may not want to process the commands right away? I'm not sure really.
Santa_Clause
2007-09-10 04:56:54
Holy Shizznit! StarBlaster doesn't know the answer to a SCAR question.
Tomorrow is the end of the world people ;)
Wizzup?
2007-09-10 05:13:22
program New;
function test: boolean;
begin
end;
begin
while not test do
wait(100);
end.
:)
elementalelf
2007-09-10 05:57:07
From: Starblaster100
A good question… sometimes you may not want to process the commands right away? I'm not sure really.
sleep is better for 10000+ ms wait times, wait is better for <10000.
the reason being is that when the process "wakes" it takes more processing cycles, but while its "sleeping" it takes less then the "wait" command.
10000 is about the cutoff point of feasability.
Wizzup?
2007-09-10 07:37:11
From: elementalelf
sleep is better for 10000+ ms wait times, wait is better for <10000.
the reason being is that when the process "wakes" it takes more processing cycles, but while its "sleeping" it takes less then the "wait" command.
10000 is about the cutoff point of feasability.
[php]procedure Wait(ms: Integer);
Waits ms milliseconds (Wait(1000) - wait 1 second).
procedure Sleep(ms: Integer);
Alias of Wait.
[/php]
Alias, isn't that just the same proc with a different name?
Starblaster100
2007-09-10 08:04:31
Someone is just too lazy to explain the differences in the manual, since it is such a minor thing
The Claw
2007-09-10 08:14:32
Yea, it has the same effects as each other but they go about it in a different way, as detailed by star in the page before
Hugolord
2007-09-10 13:34:26
From: The Claw
Yea, it has the same effects as each other but they go about it in a different way, as detailed by star in the page before
so wait is generally better?
Starblaster100
2007-09-10 15:46:47
Yes, thats correct
Bobarkinator
2007-09-10 20:21:10
Star didn't you explain once that wait sends some kind of process thing? Where it gives everything a break so you don't get lag?
Smartzkid
2007-09-10 20:49:16
From: bobarkinator
Star didn't you explain once that wait sends some kind of process thing? Where it gives everything a break so you don't get lag?
Yup.
From: Starblaster100
There is a subtle difference.
Wait uses the Process command. When you load a ton of Procedures into a SCAR loop, it will not execute them until it comes across a process command (which is in "wait") Thats why we always have tiny waits in our scripts, so SCAR can process everything we tell it to do and not lag like hell.
Sleep doesn't have this process command. It just simply waits or "puts the application to sleep" for a certain amount of time you set.
Wanted
2007-09-11 19:30:16
From: elementalelf
sleep is better for 10000+ ms wait times, wait is better for <10000.
From: Icefire908
Yea, lol, you can tell I waste to much time worried about standards and finding out the differences between certain techniques and styles. It never fails to amaze me when I find out that some times they have a major or even minor difference…
:)
Mr. Freeweed
2007-09-12 18:58:08
From: SantaClause
How about we keep a maximum of one semi-colon on each line ;)
To each their own.
I use a few while loops just depends on whether you want a check at the end of the cycle (repeat) or a check at the beginning of you code (while). just have to when when to use it. Its not a really a matter of preference.
elementalelf
2007-09-13 02:38:38
as was said before, there is actually quite a large difference between wait and sleep, i originally started programming with 1st and 2nd generation languages, which, if you dont know, are the languages that MAKE the languages most people use today.
COBOL for instance, or FORTRAN.
the guys who made scar(kaitnieks) probably just didnt think that it would get to the stage where it would make any sort of major difference.