ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: 12TimesOver on January 26, 2010, 12:36:52 PM

Title: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: 12TimesOver on January 26, 2010, 12:36:52 PM
I go back and forth for no apparent reason other than my mood I guess. I'm going to pick one and stick with it. What do you do?
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Superslayer on January 26, 2010, 12:39:51 PM
No brackets here. I do however use them in while loops if it's more than two lines.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Scrripty on January 26, 2010, 12:48:09 PM
No brackets here. I do however use them in while loops if it's more than two lines.

I do depending on how many lines also.  But one interesting thing to note:  It's a good idea to use wait 1's in your repeat loops for non or only semi time critical functions.  According to Roadkill it produces less wear and tear on your cpu and is a little more stable.

The difference between this:

Code: [Select]
repeat
until #charghost = yes

and

Code: [Select]
repeat
  wait 1
until #charghost = yes

is about 20000 iterations... :)  So you can see how much of a saving on your processor that is... and you're still doing a TON of iterations using that wait 1.  Be fun to write a little bit of code to test just how many iterations per second those do on a few computers to get an idea of the kind of issues it would cause based on processor speed.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Endless Night on January 26, 2010, 01:23:11 PM
No brackets here. I do however use them in while loops if it's more than two lines.

you have to use brackets for while and for loops if more than 1 line inside the loop is being exectuted.
And ive even had issues where euo didnt fuction correctly with 1 line inside the loop without brackets

So my advice if its not a repeat until... always use brackets.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Cerveza on January 26, 2010, 01:27:02 PM
I use them, always.

It helps me visually see what all is included in the repeat. Everything is indented nicely ;)
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Scrripty on January 26, 2010, 01:34:37 PM
No brackets here. I do however use them in while loops if it's more than two lines.

you have to use brackets for while and for loops if more than 1 line inside the loop is being exectuted.
And ive even had issues where euo didnt fuction correctly with 1 line inside the loop without brackets

So my advice if its not a repeat until... always use brackets.

In EUO 1.5 brackets for FOR loops are options if it's only one line of code.  Not sure about while's.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Endless Night on January 26, 2010, 01:36:33 PM
No brackets here. I do however use them in while loops if it's more than two lines.

you have to use brackets for while and for loops if more than 1 line inside the loop is being exectuted.
And ive even had issues where euo didnt fuction correctly with 1 line inside the loop without brackets

So my advice if its not a repeat until... always use brackets.

In EUO 1.5 brackets for FOR loops are options if it's only one line of code.  Not sure about while's.

I know thats what i said.. but i also said EUO glitches sometimes with one line and no brackets (for loops)
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: TrailMyx on January 26, 2010, 01:58:55 PM
Kinda silly to use them with a repeat/until construct.  Brackets are "implied" with the repeat/until.  So it's like having brackets for your brackets.  Redundant for sure!
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Scrripty on January 26, 2010, 02:06:33 PM
No brackets here. I do however use them in while loops if it's more than two lines.

you have to use brackets for while and for loops if more than 1 line inside the loop is being exectuted.
And ive even had issues where euo didnt fuction correctly with 1 line inside the loop without brackets

So my advice if its not a repeat until... always use brackets.

In EUO 1.5 brackets for FOR loops are options if it's only one line of code.  Not sure about while's.

I know thats what i said.. but i also said EUO glitches sometimes with one line and no brackets (for loops)


Cut me some slack.  I'm sick. :)
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Endless Night on January 26, 2010, 02:09:33 PM
lol ;)
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: manwinc on January 26, 2010, 02:51:33 PM
if you do

for #findindex 1 #findcnt
gosub Whatever

It starts you off on #findindex = 2 thats the glitch. I've seen it happen a dozen times. if you don't have brackets it will skip over your first number.


I always use brackets on my repeat untils unless its only 1 line of code inbetween. I always thought it was mandatory. I wonder if thats why they use endif in vb..... to save lines?
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Superslayer on January 26, 2010, 03:40:46 PM
if you do

for #findindex 1 #findcnt
gosub Whatever

It starts you off on #findindex = 2 thats the glitch. I've seen it happen a dozen times. if you don't have brackets it will skip over your first number.


I always use brackets on my repeat untils unless its only 1 line of code inbetween. I always thought it was mandatory. I wonder if thats why they use endif in vb..... to save lines?

I love the endif functions. I've used them in javascript before and wish they'd be employed in euo.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Cerveza on February 07, 2010, 03:45:09 AM
HAH! I KNEW IT!!

I knew there was some reason I ALWAYS use {} after a "repeat" AND "if". And now, you all will too....

if #finddist > 4
;  move #findx #findy 2
  event pathFind #findx #findy #findz

By allowing the "if" statement to execute the next line, it actually recognizes the ; (rem) statement as the condition. It would ALWAYS perform the "event pathFind".

if #finddist > 4
  {
;  move #findx #findy 2
  event pathFind #findx #findy #findz
  }

Changed to that, using the brackets, it works perfectly and ONLY executes the "event pathFind" if greater then 2 tiles away.

I didn't test it with Repeat, but I'd assume the same situation.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Khameleon on February 07, 2010, 04:00:17 AM
the if statment without brackets will always read the 2nd line weather the 1st line is commented out or blank....

not sure if alot of ppl realize this but you can also tell the if statement how many lines are in the statement.  if You ask me its very tough to keep track of this exspecially if you edit a script.

Code: [Select]
start:
if #Findking = -1 2
   ignoreitem #Findid
   goto start
does the same thing as
Code: [Select]
start:
if #FindKind = -1
   {
   ignoreitem #findId
   Goto Start
   }

but this will only read the next line if the statement is true.
Code: [Select]
Start:
If #FindKind = -1
Ignoreitem #findID ; if the statement is true this line will be read
goto Start ; this line will always be read since its not bracketed.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Scrripty on February 07, 2010, 01:28:46 PM
Yea the whole designating how many lines are behind an if thing is nice, I learned about it a while back, but it's not really necessary in EUO, the only times I could ever see using it are in a REALLY time constrained situation where you need to do something in as few lines as possible.  Say like scanning TONS and TONS of data where every line makes a difference in speed?  I have tried it, and it saves 2 lines of code in every if statement, but there's really not many real situations where it's necessary.  Easier to read imo with brackets also. :)
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: manwinc on February 07, 2010, 01:53:41 PM
I agree with Twinkle McNugget, although some scripts like my Suit Builder are hard to read even with brackets  :( I can't even understand it anymore.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Paulonius on February 07, 2010, 07:29:25 PM
Just a little feedback on an idea I saw in this thread posted by Twinkle McNugget and credited to Roadkill regarding putting a wait 1 into loops.  I was running a script that runs a mainloop with lots of checks that for the most part won't do anything, so it cycles really fast.  When I had two of them running it amped my CPU load from 5% to 44%.  When I dropped a "Wait 1" into the mainloop it dropped the load back down to 15%.  Something to think about when building scripts that hold a loop for any amount of time.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Scrripty on February 07, 2010, 08:02:43 PM
Just a little feedback on an idea I saw in this thread posted by Twinkle McNugget and credited to Roadkill regarding putting a wait 1 into loops.  I was running a script that runs a mainloop with lots of checks that for the most part won't do anything, so it cycles really fast.  When I had two of them running it amped my CPU load from 5% to 44%.  When I dropped a "Wait 1" into the mainloop it dropped the load back down to 15%.  Something to think about when building scripts that hold a loop for any amount of time.

UO is based on pretty big waits for actions... anything faster than like 1/10th of a second is pretty much a waste unless it's SERIOUSLY important you do it like RIGHT NOW. :)  Or doing TONS of calcs...  You can take it a step further Paul for great control with using like #sysTime or #sCnt/2  :)  According to RK and my own testing it sure helps scripts not be so "laggy." Glad that helped ya.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: manwinc on February 18, 2010, 12:13:11 PM
Yeah, in ALOT of my scripts I have things like.

set %Lobject_Timer #Scnt2 + 10
%Cast_Timer #Scnt2 + %Fcr_Delay

For Generic things, AKA You can't use an object yet, or you can't cast yet. And then beyond that you also set the rest of your timers.

set %EO1 #scnt + 360

etc etc
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Superslayer on February 18, 2010, 12:25:56 PM
the if statment without brackets will always read the 2nd line weather the 1st line is commented out or blank....

not sure if alot of ppl realize this but you can also tell the if statement how many lines are in the statement.  if You ask me its very tough to keep track of this exspecially if you edit a script.

Code: [Select]
start:
if #Findking = -1 2
   ignoreitem #Findid
   goto start
does the same thing as
Code: [Select]
start:
if #FindKind = -1
   {
   ignoreitem #findId
   Goto Start
   }

but this will only read the next line if the statement is true.
Code: [Select]
Start:
If #FindKind = -1
Ignoreitem #findID ; if the statement is true this line will be read
goto Start ; this line will always be read since its not bracketed.

I've been using this as of late, and found that it also works with 'else' statements.  Very cool feature imo.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Paulonius on February 18, 2010, 12:38:17 PM
EN, can you throw up an example?
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Endless Night on February 18, 2010, 05:40:09 PM
EN, can you throw up an example?

???? Of ?
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Superslayer on February 18, 2010, 08:40:36 PM
In the event Paul may have meant me,:

This is the same :
Code: [Select]
if %Alpha = %Delta
{
  do stuff
  do more stuff
  finish doing stuff
}
else
{
  don't do stuff
  don't do anything else
  finish not doing something
}

as this:
Code: [Select]
if %Alpha = %Delta 3
  do stuff
  do more stuff
  finish doing stuff
else 3
  don't do stuff
  don't do anything else
  finish not doing something
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: UOMaddog on February 18, 2010, 09:55:17 PM
I wish EUO would let me do my traditional Java formatting:

Code: [Select]
if this==that {
   blah blah
   yadda yadda
}

do {
  sumthin sumthin
} while fail==true

I like my brackets to start at the end of the line and then finish off the statement. It even makes 1 liners look nice. This is the standard format that Eclipse uses and I would personally love to have sex with Eclipse because it makes scripting so easy!
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Paulonius on February 18, 2010, 11:18:10 PM
I did SS, thank you.  Sorry EN, not getting enough sleep.  

I mean I did mean you in that previous post, not "I did have sex with eclipse..."
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Katu on March 25, 2010, 01:24:32 PM
I use em, becouse i think it makes the code look cleaner. Im used to C languages so brackets makes sense. Ofcourse with "IF's" i dont always use, if theres just one line to do. In some cases, there needs to be lots of "IF's" and set variable then return. If using brackets, it takes almost 2x lines to do it. Then i might use the number to let EUO know, how many lines to process.
Ill use brackets even with subs.
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: rana70 on March 26, 2010, 09:24:00 AM
There are still places in the UO script Community
 .. where a script without brackets ...
even if it works ...
is considered tooooo bugy to be proven :-)

 ;) :'(
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: BadManiac on March 26, 2010, 07:22:33 PM
Always brackets and indentation everywhere. Consistency is king in programming. Brackets with if's, while's, repeat's, sub's. ALWAYS brackets!!!
Title: Re: REPEAT/UNTIL Loops - Do you use brackets or none?
Post by: Katu on March 26, 2010, 11:07:43 PM
Always brackets and indentation everywhere. Consistency is king in programming. Brackets with if's, while's, repeat's, sub's. ALWAYS brackets!!!
Agree 100%