Order of operation on "if" statement

So I have this code

if playerwhoholded.Name == owner.Name and OwnerCache.Eggs.Value > Price or OwnerCache.Eggs.Value == Price then

WIll this check if the playerwhoholded is the owner and if the money is equal or greater than the price?

I’m confused about the ‘or’, I think it might cancel out this

if playerwhoholded.Name == owner.Name
``

Logical disjunction have lower precedence than logical conjunction.

Therefore the script in your post would be equivalent to (playerwhoholded.Name == owner.Name and OwnerCache.Eggs.Value > Price) or OwnerCache.Eggs.Value == Price.

See the reference manual: Lua 5.1 Reference Manual

I presume you mean:
playerwhoholded.Name == owner.Name and (OwnerCache.Eggs.Value > Price or OwnerCache.Eggs.Value == Price)

1 Like
if (playerwhoholded.Name == owner.Name and OwnerCache.Eggs.Value > Price) or (OwnerCache.Eggs.Value == Price) then

end

You can use parentheses to connect “and” and “or” statements together. I’m not sure how you want it, but this is just an example in case the “and” or “or” are interfering with each other. (Sorry I’m not good at describing it)

1 Like

just use >= to check if a number is greater than or equal to the other number

1 Like

That’s not what his problem is.

Thanks for the responses
@RichPerson03return and @Blockzez

Would this work:

if (playerwhoholded.Name == player.Name) and (OwnerCache.Eggs.Value > Price or OwnerCache.Eggs.Value == Price)

Yeah depending on what you want it to do.
I’ll try my best to give examples.

apples and (bananas or peaches) – Some apples that go along with rather bananas or peaches

(apples and bananas) or peaches – Rather have apples and bananas or you could just have some peaches