How do i run a loop INSTANTLY? (read desc)

ok lemem explain…

Its not a world generator, its a… world simulator???

im not sure how to word it but its calculation the world population, mood, date, score, age, danger, economy, wants, and some other small things. All of this goes into calculating eachother so if they are unhappy there more likley to want happiness…

Its kidna hard to explain

okay but why do you have to do it instantly though

At the end of each “shift” based on how good you did the world will advance the next day, and i need to simulate all of this advancement very fast so that when you return its already done

Basically you want to create a sort of timestep system?

i already did that, see when your at your shift the simulations go by every second, but when yourt home i need them to go by INSTANTLY so that when your back its as if your whole world has been advancing for hours even if its only been a few seconds

Well now we finally know what you wanna do so show us the code you’re working with right now

i dont have any because im trying to figure out how to simulate all of this instantly, i already have had the simulation code done for days but now i need a way to simulate it instantly

You can indeed run a while .. do loop without a yield, but there is a limit;

local limit = 100
local count = 0

while true do
	count += 1
	print(count)

	if count >= limit then
		task.wait()
		print("Count reset to 0.")
		count = 0
	end
end
Statistics

Count from 0 to 100 takes 4 milliseconds.
From 0 to 0 takes 45 milliseconds.


This loop runs instantly (or as fast as the tick speed allows) 100 times in a row, then yielding for a millisecond to avoid a timeout.

However, there is a reason it requires a yield, because it’s just too straining to do without. A safer option would be to use a coroutine or task.spawn to use multiple threads which could all run the same loop independently.

Okay, then show us the code that’s what I said

i. dont. have the. code.
thats why i made this post, so someone could tell me how to make my simulation code (works fine) run instantly

You shuldnt need my simulation code because it has nothing to do with the loop i need

2 Likes

if you want to skip some amount of time in a simulation and each step needs to be processed then you need to use a loop that only waits one out a few hundred times

If you’re not going to show your simulation code how do you expect us to help you

you’re already doing a terrible job explaining what your trying to do so we have no idea, how you want it

yes. i have that code. that code needs to just run very VERY fast. if you really want something heres the stepper code:

CWD.Event:Connect(function(PR)
	if PR == "Started" then
		while WrldData.Cont == true do

                        --Does simulation here

			task.wait(WrldData.GameTick)
			print(WrldData.Cont)

		end
	elseif PR == "SleeperrMode" then
		
		-- here i need instant simulation
		
	end
end)

Okay, finally you’ve given us some code to look at, but we need to see how your progressing the simulation regularly so we can see how to do it “INSTANTLY”

so every gametick (1 second by default) the game makes ALL the calculations needed to progress

in “sleeper mode” i need it to instead of waiting a gametick, do it INSTANTLY X amount of times

put the simulation in a function

run the function in a loop and wait less time

theres no way to do it instantly unless you have a computer with infinite processing power

I seriously don’t know why you don’t wanna show the code, we need too see the how you make it progress

i have to go but ill be back later

1 Like

lil bro when you come back you better show us the progression code

1 Like