-
Comparing a number sequence
-
Can’t figure out how to compare it
what do you mean?
if Number1 > Number2 then
You can’t compare numbersequences like that, it errors
Here are a few links you can use:
You don’t use the actual Number1 and Number2. Use the real number, such as if 3 < 5 then – If 3 is less than 5 then do so and so…
I know, you cant compare a numbersequence it errors…
What is the error that you are getting when using this method?
What are you trying to compare in the number sequence?
local NumberSequence1 = NumberSequence.new{
NumberSequenceKeypoint.new(0, 0), -- (time, value)
NumberSequenceKeypoint.new(.5, .75),
NumberSequenceKeypoint.new(1, 1)
}
local NumberSequence2 = NumberSequence.new{
NumberSequenceKeypoint.new(0, 0),
NumberSequenceKeypoint.new(.5, .75),
NumberSequenceKeypoint.new(1, 1)
}
local NumberSequence3 = NumberSequence.new{
NumberSequenceKeypoint.new(0, 0),
NumberSequenceKeypoint.new(.1, .4),
NumberSequenceKeypoint.new(1, 5)
}
function areSequencesEqual(sequence1, sequence2)
for i, keypoint in pairs(sequence1.Keypoints) do
local keypoint2 = sequence2.Keypoints[i]
--checking each keypoint one by one(we don't need to compare time and value, Roblox does it for us)
if not keypoint2 or keypoint ~= keypoint2 then
return false
end
end
--in order for them to be equal, they must have the same length
--this check is added in case sequence1 keypoints are less than sequence2 causing some keypoints to pass unchecked
return (#sequence1.Keypoints == #sequence2.Keypoints)
end
print(areSequencesEqual(NumberSequence1, NumberSequence2)) --true
print(areSequencesEqual(NumberSequence2, NumberSequence3)) --false