ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Kryz on August 22, 2015, 09:17:46 PM

Title: Plus or Minus...
Post by: Kryz on August 22, 2015, 09:17:46 PM
Im looking for a quick way to use a range in an expression.

IE if A = B +-1
 
If A is equal to B, B+1, B-1

Am I stuck with If A = B || A = B + 1 || A = B - 1 Or is there a quicker way to do it?
Title: Re: Plus or Minus...
Post by: TrailMyx on August 22, 2015, 09:58:03 PM
If you do a little bit of algebra, you can simplify what you're looking for:

Code: [Select]
set %a 6
set %b 5
set %c 1 ; range
if ( abs ( %a - %b ) <= %c )
{
  display ok within range
}
stop
Title: Re: Plus or Minus...
Post by: manwinc on August 22, 2015, 09:59:14 PM
set %A 1
set %B 2
set %Range 1
If abs( %A - %b ) <= %Range
Display ITS IN RANGE
Display its not in Range
Title: Re: Plus or Minus...
Post by: manwinc on August 22, 2015, 09:59:42 PM
Tm beat me by seconds!
Title: Re: Plus or Minus...
Post by: TrailMyx on August 22, 2015, 10:00:38 PM
Tm beat me by seconds!

Nearly exact same code!  Great minds DO think alike!  :)
Title: Re: Plus or Minus...
Post by: Kryz on August 22, 2015, 10:31:56 PM
Thank you all!
Title: Re: Plus or Minus...
Post by: KaliOfLS on August 23, 2015, 04:06:43 AM
You two are just so cute. 

I would do it one step further and make a sub routine.

Code: [Select]
gosub InRange 6 5 1
if #result
   display ok It's in range!
else
   display ok come a little closer baby.
halt

sub InRange
    if abs ( %1 - %2 ) <= % 3
        return #true
return #false