Boogiepop210 Posted November 19, 2023 Share Posted November 19, 2023 function Formula(prefab, u1, u2, xRange, yRange) local player = ThePlayer local playerPos = player:GetPosition() for x = -xRange, xRange do for y = -yRange, yRange do local z = math.abs(x-u1) + math.abs(y - u2) while z == 1 do local spawnPos = Vector3(playerPos.x+x, playerPos.y, playerPos.z+z) SpawnPrefab(prefab).Transform:SetPosition(spawnPos:Get()) end end end end So, I'm trying to make a square of sandspikes with this command, but whenever I use it, it goes on infinitely and crashes. I've been using it like this: Formula("sandspike", 1, 1, 1, 1) Sorry if this is insanely obvious, I've never used while loops lol. Link to comment https://forums.kleientertainment.com/forums/topic/152506-help-with-while-loop-solved/ Share on other sites More sharing options...
Boogiepop210 Posted November 19, 2023 Author Share Posted November 19, 2023 nvm I found a different method so it's fine. Link to comment https://forums.kleientertainment.com/forums/topic/152506-help-with-while-loop-solved/#findComment-1680542 Share on other sites More sharing options...
Yuuko Posted November 19, 2023 Share Posted November 19, 2023 What is changing the Z value? The while loop repeats until something changes Z to not longer equal one and I don't see anything changing that. idk lua so there may be some language thing I'm missing where this is not the correct answer, but in the languages I do use the while loop must include an iteration or it will be infinite (or never proc depending) Also - do you actually need a while loop here? The do x and do y are iterating over your position, what is the while loop repeating for? Link to comment https://forums.kleientertainment.com/forums/topic/152506-help-with-while-loop-solved/#findComment-1680558 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.
Please be aware that the content of this thread may be outdated and no longer applicable.