Quick question for scripters

Why do some scripters put “not <” instead of “>=”? Is there a reason, or is it just preference?

3 Likes

Some people do “not (VAR1 < VAR2)” to see if VAR1 is bigger than or equal to VAR2.

You could say “not (VAR1 < VAR2)” is equal to "VAR1 >= VAR2"

2 Likes

They do the exact same thing, so I believe it’s just preference.

1 Like

I don’t believe it’s a preference. If I were to say,

local cake = 2
local carrot = 2

if not (cake < carrot) then
    print("hello!")
end

even if the values are the same, it will run.

2 Likes

In a way, it is really just a preference. In my opinion, it’s easier to just do cake >= carrot then

local cake = 2
local carrot = 2

if cake >= carrot then
    print("hello!")
end

This requires less typing and saves some time, even if just a second. Same effect, different form.

5 Likes

I guess it’s like a semi-preference. I would prefer your method, because it requires to use less of your thinking.

>= is better practice in general since trying to tie in raw boolean modifiers with numbers can confuse a person

besides >= takes less work to type

5 Likes

it’s also better in the long run and helps with code readability when you need to update it in the future.

3 Likes

I prefer this method of mine:

local a= 3
local b= 10

local sum = a+b
local product = a*b

local c = 0
for i=1,math.fmod(sum,product) do
	c += 1*product
end
local final = c-a*b

if final+(((((a-a*2)*-1)*b)/10))-final>=b then
	print("a is greater than or equal to b")
end

3 Likes

It’s like saying

He ate a bag of doritos when you could have said He didn't not eat a bag of doritos, the only difference is that more is being said in the second one and it is harder to understand for a moment.

In some situations you want to say He did not eat a bag of doritos and he did not eat a cake which you can say He didn't eat a bag of doritos or a cake

local a,b = 5,10
local c = 0
c = not (a > b) and b or a
print(c)

It’s really just a habit for some people that like saying “not <”, same with

"if … then no code else code end

The not word has its uses though

3 Likes

Alright y’all thanks for the answers. Your answer specifically brought up another question I’ve frankly had for a while.

c = not (a > b) and b or a

What does this mean? I understand the initial part is setting the variable to be a bool, but how do the “and” and the “or” impact the statement? What is it saying and why does that work?

the “or a” portion of the statement is saying that if the other part, the “not (a > b) and b” portion, does not meet the criteria, then make c = to a

1 Like

That’s a Lua idiom for representing ternary operators, you’re better off using an ‘if then else’ expression introduced by Luau’s implementation.

local c = if not (a > b) then b else c

1 Like

What I understand from this is that, when setting a variable to a bool “and” an item, if the bool is true the variable is set to the item, otherwise it remains nil? Likewise, the “or” sets the variables to be either of the options, prioritizing the true/ not nil one? If both are true, then does the “or” reliably favor one of the options?

1 Like

It’s basically a more compact version of:

local c;
if not (a > b) then
    c = b
else
    c = a
end

the or statement being the else statement

You can read more at the lua site which in my opinion, explains it better than we could, about ternary operators and has a lot more examples:
http://lua-users.org/wiki/TernaryOperator