Author Topic: The need of brackets.  (Read 6038 times)

0 Members and 1 Guest are viewing this topic.

Offline camotbikTopic starter

  • Sr. Member
  • *
  • Posts: 349
  • Activity:
    0%
  • Reputation Power: 3
  • camotbik has no influence.
  • Gender: Male
  • Hello! I'm a UO addict.
  • Respect: +38
  • Referrals: 0
    • View Profile
The need of brackets.
« on: October 18, 2011, 05:06:54 AM »
0
I saw that many newcomers to easyuo are having the same old problem - they are not using brackets on statements. So I would say always use brackets when possible (except if there's only one line of code(example1)). The main purpose of brackets is to determine the margins of a statement(see example 2).
The usage of brackets.

Example1 - one line (if) statement, that doesnt need any brackets.
Code: [Select]
if #hits < #maxhits                   ; if hits get lower than maximum hits
event macro 1 1 Guards                ; say Guards

In this example if your hits get lower than maxhits, you will call Guards. As in this example we are only using 1 line (calling the guards) after the if statement, so we have no need for brackets.

Example2 - multiple line (if) statement, that needs brackets.
Code: [Select]
if #hits < #maxhits                   ; if hits get lower than maximum hits                
{                                     ; open statement if #hits lower than maxhits
event macro 1 1 Guards                ; say Guards
event macro 15 28                     ; cast spell greater heal
target                                ; wait for target
event macro 23 0                      ; target self
wait 40                               ; wait 2 seconds
}                                     ; close statement if #hits lower than maxhits

In this example if your hits get lower than maxhits, you will call Guards, then you cast greater heal spell on yourself and wait for 2 seconds. As in this example we are using more than 1 line after the if statement - we need to use brackets, so our code would work the way we want.

Example2.1 -  multiple line (if) statement, that needs brackets, but doesnt have them. -- this is the bad way - the way you dont want to do this.
Code: [Select]
if #hits < #maxhits                   ; if hits get lower than maximum hits                
event macro 1 1 Guards                ; say Guards
event macro 15 28                     ; cast spell greater heal
target                                ; wait for target
event macro 23 0                      ; target self
wait 40                               ; wait 2 seconds

What does happen here? Well if you get your hits bellow maxhits, you will call guards, but in the mean time while you are at your maxhits, you will cast greater heal on yourself and wait 2 seconds. If you ask yourself why? Well because the margins of the statement arent set and you will execute only one line after the if statement(see example1).

Example 3 - Usage of brackets in other circles.
if / else
Code: [Select]
if #hits < #maxhits
{                                     ; open statement
event macro 1 1 Guards                ; say Guards
event macro 15 28                     ; cast spell greater heal
target                                ; wait for target
event macro 23 0                      ; target self
wait 40                              ; wait 2 seconds
}                                     ; close statement
else
{                                     ; open statement
event macro 1 1 Everything seems fine ; say Everything seems fine
wait 40                               ; wait 2 seconds
}                                     ; close statement
while
Code: [Select]
While #hits < #maxhits                ; while hits are less than maxhits
{                                     ; open statement
event macro 1 1 Guards                ; say Guards
event macro 15 28                     ; cast spell greater heal
target                                ; waitfortarget
event macro 23 0                      ; target self
wait 40                              ; wait 2 seconds
}                                     ; close statement
for
Code: [Select]
for %i 1 20                           ; repeat 20 times
{                                     ; open statement
.....
.....
}                                     ; close statement

I hope this will help some of the newcomers to understand the need of brackets.
« Last Edit: October 18, 2011, 05:23:01 AM by camotbik »
What you witness -- is whatver..
uogamers hybrid.

Offline Endless Night

  • Global Moderator
  • *
  • *
  • Posts: 5467
  • Activity:
    0%
  • Reputation Power: 62
  • Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!Endless Night is awe-inspiring!
  • Respect: +393
  • Referrals: 1
    • View Profile
Re: The need of brackets.
« Reply #1 on: October 18, 2011, 05:24:45 AM »
0
nice and much needed tutorial camotbik
Outlaw Josey Wales - "Manwink, A Long Gone Scripty, and Endless are always teasing us with their private sections lol. What there realy saying is scripters rule and users drool."
Briza - "Your a living breathing vortex of usefulness."

Offline Crome969

  • Elite
  • *
  • *
  • Posts: 2098
  • Activity:
    0%
  • Reputation Power: 25
  • Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.Crome969 is on the verge of being accepted.
  • Gender: Male
  • UO Enthusiast
  • Respect: +211
  • Referrals: 10
    • View Profile
    • ScriptSDK
Re: The need of brackets.
« Reply #2 on: October 18, 2011, 07:05:37 AM »
0
Thanks buddy, you did a great job. Newbies need this.. and Oldies might find something they not knowed yet:)

Tags: