variable min/max function?

jleips2600

New Member
Reaction score
4
Is there any sort of function to limit a variables max/min?

ei) x = 0
constant_max = 20
constant_min = -10

magicalfunction(x, constant_max, constant_min)
if x > y
x = y
elseif x < z
x = z
endif
return x

doing this would allow you to check if x has gone beyond the max or min, and if it has, set it to the max or min.

Im pretty sure there's a term for this function, but alas I'm not a programmer.
Regardless, does such a function exist in Galaxy Editor that I just can't seem to find it?

Thank you in advanced sweet, sweet community =D
 

jleips2600

New Member
Reaction score
4
ahhh clamp! that's it, thank you so much!

****edit****
do you have to clamp the variable through 'set variable' function?
 

Advice D.

New Member
Reaction score
11
A quick search reveals nothing in the built-in functions, however you've pretty much got your function there. Just recreate that in GUI/JASS and you'll be golden.

Also, the term that comes to mind is "clamp" e.g. Clamp x to between -10 and 20.

EDIT: Ha, missed that. Ignore this.
 

ZugZugZealot

New Member
Reaction score
33
Galaxy no longer supports pointers. So basically "value = Clamp(value, min, max)" is what you're left with.

Before, a function could be made to take "refClamp(&value, min, max)" but that's no longer the case.

Also, just clamp the value when you change it...
example...
value = Clamp( value + x, 9001, 2147483648)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top