Script timeout error when training perceptron

I have a module script containing 220k+ lines string. I want to use this string to train a perceptron.
Here is my function:

function(pos_tagger, train)
	local done = false
	local training_set = {}
	local lines = train:gmatch("(.-)[\n\r]")
	while not done do
		local found_end_of_sentence = false
		local sentence = {}
		while not found_end_of_sentence do
			local sent = lines() or ""
			local func = string.gmatch(sent, "[^%s]+")
			local curr_word, tag, chunk_tag = func(), func(), func()
			if curr_word == nil then
				found_end_of_sentence = true
			elseif curr_word == "END_OF_TRAINING_FILE" then
				found_end_of_sentence = true
				done = true
				table.insert(sentence, {curr_word, tag})
		table.insert(training_set, sentence)
	pos_tagger:train(training_set, 8)

But the string is too big and the proccess takes some time. But if I use wait() in my loop this takes too much time and it’s litterally impossible to load in time. How to ignore script timeout and continue executing?

you can disable script timeout by executing this in the studio command bar

settings().Studio.ScriptTimeoutLength = -1

I have already set this to -1.

I tend to put something like this in long functions at the highest loop that makes sense

local lastYield = tick()
local timeBetweenYields = 0.25

--Inside your loop
if tick() - lastYield >= timeBetweenYields then
    lastYield = tick()

This way I don’t yield every loop, but my long functions don’t time out by still giving roblox time to run other stuff.

1 Like