It’s supposed to print false. I explained the math. >
is not a valid expression. Why do you want to store the operator itself as a variable?
greater_than
is true if -10 is greater than 0 (which it isn’t), false otherwise (which it is false)
It’s supposed to print false. I explained the math. >
is not a valid expression. Why do you want to store the operator itself as a variable?
greater_than
is true if -10 is greater than 0 (which it isn’t), false otherwise (which it is false)
yes dont worry i understand that part, but the entire script works, its jsut that i have like 20 lines of code copied 4 times to just change the < and > , i wanna simplify it using a variable and only one function, am currently trying to use what my brother gave me not sure if itll work tho
There is still no reason to set a variable. It would take more time and ultimately be less efficient. Not to mention just not possible.
local x = 5
local isEqualToZero = x == 0
This previous block checks that x == 0 to zero and assigns the boolean to a variable.
would it be less efficient then having the same 20 lines 4 times with only 4 keys different? cause the way i did it in the beginning is very inefficient to me, trying to make it better and simpler
Please share the four lines you wish to simplify, because it’s more likely you need to make a new function that contains those four lines. The code is very repetitive.
i know im trying to remove the repetition and to make it into one function, heres the lines:
local function downfunction()
if card.ImageTransparency == 0 and script.Parent.Parent.Visible == true and loading == false then
local obj = frame:FindFirstChild(selected)
local closest
for i,v in pairs(frame:GetChildren()) do
if v.Position.X == obj.Position.X then
if obj.Position.Y.Scale - v.Position.Y.Scale < 0 then
if closest then
if frame:FindFirstChild(closest).Position.Y.Scale - v.Position.Y.Scale > 0 then
closest = v.Name
end
else
closest = v.Name
end
end
end
end
if closest then
obj.BorderSizePixel = '0'
selected = closest
frame:FindFirstChild(closest).BorderSizePixel = '2'
end
end
end
local function leftfunction()
if card.ImageTransparency == 0 and script.Parent.Parent.Visible == true and loading == false then
local obj = frame:FindFirstChild(selected)
local closest
for i,v in pairs(frame:GetChildren()) do
if v.Position.Y == obj.Position.Y then
if obj.Position.X.Scale - v.Position.X.Scale > 0 then
if closest then
if frame:FindFirstChild(closest).Position.X.Scale - v.Position.X.Scale > 0 then
closest = v.Name
end
else
closest = v.Name
end
end
end
end
if closest then
obj.BorderSizePixel = '0'
selected = closest
frame:FindFirstChild(closest).BorderSizePixel = '2'
end
end
end
local function rightfunction()
if card.ImageTransparency == 0 and script.Parent.Parent.Visible == true and loading == false then
local obj = frame:FindFirstChild(selected)
local closest
for i,v in pairs(frame:GetChildren()) do
if v.Position.Y == obj.Position.Y then
if obj.Position.X.Scale - v.Position.X.Scale < 0 then
if closest then
if frame:FindFirstChild(closest).Position.X.Scale - v.Position.X.Scale < 0 then
closest = v.Name
end
else
closest = v.Name
end
end
end
end
if closest then
obj.BorderSizePixel = '0'
selected = closest
frame:FindFirstChild(closest).BorderSizePixel = '2'
end
end
end
there was a fourth function, upfunction(), but i removed it to try and simplify it all but the code was the same as these
oh and i didnt mention it but the code checks the closest textlabel either up, right, left or down, and i dont need to fix it since it works, just to simplify things makes it alot better in my opniion
You have given us too much code here. Only show the code that is necessary.
Looks like you’re having an xy problem. You actually want to compare multiple numbers in a cleaner fashion, but you instead obscure this question with “how do i store an operator in a variable”. You should be asking only about your goal without presupposing a method that isn’t appropriate.
all the code i have given is needed for the script to function correctly, so im not sure where i have given too much code. sorry if i did tho
and my goal is to store an operator in a variable, or anything equal to that, im not sure how else to explain what im trying to achieve
It is impossible to store an operator in a variable.
This is a more complex issue and that is not a possible solution. The best route is to use a function and place your if statements in there.
Simple answer: You cannot make an operator a variable. Any operator in lua requires having a product on both sides to make a result. So, you will not be able to make var: <, >, +, -, … etc
alright thank you, i figured i couldnt but my question is, how would i make something work equally to that
and that would require having 4 different possibilites seeing as there are 4 directions correct?
also would it be possible to store X or Y in a variable? ex:
part.Position.var1
something like that
Yes, storing those values are possible.
local x = Frame.Position.X
A method you can use is a function for each operation you are attempting:
function isEqual(new, old)
return new == old
end
function isHigherThanZero(new, old)
return new - old > 0
end
function isLowerThanZero(new, old)
return new - old < 0
end
i also found out that doing
part.Position[var1]
also works correctly
the script fully functions now im not sure how or why it works but i tested out the line of code my brother gave me and it works, heres the line
if num1*(obj.Position[axis2].Scale - v.Position[axis2].Scale) > 0 then
so yeah, thanks for the help tho Dracius
I don’t think there is any reason to multiply the expression by the num1 variable. But if it works, it works.
Nice job, and no problem. Cya around!
cya, have a nice day and im not sure why i have to multiply it but like you said, if it works, it works