ScriptUO
Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started 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?
-
No brackets here. I do however use them in while loops if it's more than two lines.
-
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:
repeat
until #charghost = yes
and
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.
-
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.
-
I use them, always.
It helps me visually see what all is included in the repeat. Everything is indented nicely ;)
-
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.
-
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)
-
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!
-
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. :)
-
lol ;)
-
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?
-
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.
-
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.
-
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.
start:
if #Findking = -1 2
ignoreitem #Findid
goto start
does the same thing as
start:
if #FindKind = -1
{
ignoreitem #findId
Goto Start
}
but this will only read the next line if the statement is true.
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.
-
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. :)
-
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.
-
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.
-
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.
-
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
-
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.
start:
if #Findking = -1 2
ignoreitem #Findid
goto start
does the same thing as
start:
if #FindKind = -1
{
ignoreitem #findId
Goto Start
}
but this will only read the next line if the statement is true.
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.
-
EN, can you throw up an example?
-
EN, can you throw up an example?
???? Of ?
-
In the event Paul may have meant me,:
This is the same :
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:
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
-
I wish EUO would let me do my traditional Java formatting:
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!
-
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..."
-
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.
-
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 :-)
;) :'(
-
Always brackets and indentation everywhere. Consistency is king in programming. Brackets with if's, while's, repeat's, sub's. ALWAYS brackets!!!
-
Always brackets and indentation everywhere. Consistency is king in programming. Brackets with if's, while's, repeat's, sub's. ALWAYS brackets!!!
Agree 100%