Is there ANY efficient way to check every single condition without 1 resulting in being false while making 1 condition result to true?

Let’s say I create 3 points, A B and C, which are all straight in a line. Each point should not be too near each other. My code checks the last created point when deciding whether the point should be moved in case the points are too near each other. A is created first, and since the last created point is nil, A is just created like normal. B is created, and my script knows that A was last created, so B is repeatedly destroyed and created in a different place on the line until it is either far or just not too near A. Now, C is created. as I said earlier my script checks the last created point only, so while it checks B, A is ignored, so there is a possibility of C being too near A.

I really despise messy code, so I need an efficient way to make everything evaluate to true. My current code gives no errors and no warnings, everything works except for that. If I use a for loop, it just loops, and ignores the last time it looped. I thought of using coroutines, but maybe when 1 coroutine is done, another coroutine messes it up by changing it until THAT condition for that point is true.

This is a fairly convoluted explanation, could you give a brief summary of exactly what you’re trying to achieve?

TL;DR: I want every condition to evaluate to true without 1 check messing everything up and making 1 condition false again

if something or true then

Try this. So even if that something is false, the code in the body of the conditional statement will be executed.

Since A, B, and C are all in a straight line, that means it is linear. What this means is that the equation you use for your line is also linear, so if you just force the next point on the line to be a non-negative addition to the last point on the line, it cannot possibly be near a previous point.

An example of this is, let’s say, that your equation of a line is f(t) = t<2,1,1>

if the first point on the line is t = -5, then you just need to make sure the next point on the line is t > -5, and keep doing this for each point on the line. Then, let’s say, that the next point on the line after t = - 5 is t = -1, then you just need the point after t = -1 to be t > -1, this will ensure it still fits the criteria of t > -5.

For the points t = -5, -1, and 3 this gives us:

t = -5: <-10, -5, -5>
t = -1: <-2, -1, -1>
t = 3: <6, 3, 3>

If you need to create points on a line going infinitely in either direction, consider running this solution in both directions. i.e. starting with the point t = 0, then checking for points > 0 and also points < 0, running the same algorithm I indicated above. For the case of < 0, you just need to switch the > in the algorithm above to a <

3 Likes

I’ll try this out in a bit, I’m on my study laptop at the moment

1 Like

That was actually simpler than I thought! Thanks!
WorkingLightningModule

Hey, mind helping me with this, when creating points some still appear near each other but it happens rarely. Here’s my code:

local lerpAlpha = random:NextNumber(0, 0.2 + ((i-1)/10))
local lerpCFrame = point1.CFrame:Lerp(point2.CFrame, lerpAlpha)
if #tableOfLerps ~= 0 then
	local lastNumTable = tableOfLerps[#tableOfLerps]
	local lastnum = lastNumTable[2]
	lerpAlpha = random:NextNumber(lastnum, (lastnum-0.2) + ((i-1)/10))
	lerpCFrame = point1.CFrame:Lerp(point2.CFrame, lerpAlpha)
	local lastTable = {lerpCFrame, lerpAlpha}
	table.insert(tableOfLerps, lastTable)
else
	local lastTable = {lerpCFrame, lerpAlpha}
	table.insert(tableOfLerps, lastTable)
end

How would I make this work? (Sometimes the lerp alpha gets higher than 1!)

EDIT: Found a (probably temporary) SOLUTION: lerpAlpha = random:NextNumber(lastnum, lastnum+random:NextNumber(0.2, 0.4)) EDIT 2: I’m just being dumb random:NextNumber(lastnum+0.2, lastnum + (random:NextNumber(0.3, 0.4)))