Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


math.clamp

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Thu May 12, 2022 2:12 am    Post subject: math.clamp Reply with quote

Code:
function math.clamp(value, min, max)
  if value < min then
    value = min
  elseif value > max then
    value = max
  end
  return value
end


function that compares value with min and max and replace it with min or max and return the value

_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
LeFiXER
Grandmaster Cheater Supreme
Reputation: 20

Joined: 02 Sep 2011
Posts: 1055
Location: 0x90

PostPosted: Thu May 12, 2022 6:24 am    Post subject: Reply with quote

Alternative:
Code:

function clamp(n, low, high)
  return math.min(math.max(n, low), high)
end
Back to top
View user's profile Send private message
Corroder
Grandmaster Cheater Supreme
Reputation: 75

Joined: 10 Apr 2015
Posts: 1667

PostPosted: Thu May 12, 2022 9:03 pm    Post subject: Re: math.clamp Reply with quote

Frouk wrote:

function that compares value with min and max and replace it with min or max and return the value


I don't think this is the right explanation for math.clamp, at least you try to give a more specific explanation to the readers.

What is math.clamp in Lua?. Is it useful or no and how it’s working?.



Code:
math.clamp(x, min, max) clamps a number (x) between min and max. If it’s greater than max, it’ll return max. If it’s lower than min, it’ll return min. Otherwise, it’ll return x. You could’ve just checked the wiki, though.


https://developer.roblox.com/en-us/api-reference/lua-docs/math

or

Code:
“It takes 3 values. X, min and max. If X is in the range between min and max it returns X. If X is lower than min it returns min and if X is higher than max it returns max.

This can be useful for tons of applications, but a good example would be constraining rotation on an axis. If you want a player to control the rotation of a brick on the Y axis but only in a 90 degree window you could clamp it’s total rotation.”

_________________
Stealing Code From Stolen Code...
And Admit It.. Hmmm....Typically LOL
Back to top
View user's profile Send private message
Frouk
Master Cheater
Reputation: 5

Joined: 22 Jun 2021
Posts: 489
Location: mov dword ptr [Ukraine]

PostPosted: Fri May 13, 2022 12:05 am    Post subject: Reply with quote

i was lazy to write the right explanation
_________________
void(__cdecl *Haxing)(HWND hGameWindow)
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites