Page 1 of 1

Stack overflow error

Posted: Fri Dec 20, 2013 10:47 am
by LocalFire
So I'm using a script to compare lvls of party members and then match them but I'm getting a stack overflow error

That means the script is repeating over and over right, into infinity. Heres my script.

Code: Select all

function LvlComp()
if party:getChampion(2):getEnabled()==true then

repeat

OrdinalScript.getChampionWithOrdinal(2)
:levelUp()

until  OrdinalScript.getChampionWithOrdinal(1):getLevel()== OrdinalScript.getChampionWithOrdinal(2):getLevel() 
end
If I'm thinking about this right then shouldn't it stop once the levels equalize? In the editor it will match the levels and then everythings fine for a a couple of seconds before I get the error.

How can I fix this?

Re: Stack overflow error

Posted: Fri Dec 20, 2013 11:51 am
by Xanathar
How is LvlComp triggered ?

Anyway, the code enters an infinite loop if champion 2 is already the same level or greater than champ1.

I'd change the code to:

Code: Select all

function LvlComp()
	if (party:getChampion(2):getEnabled()) then
	
		local C1 = OrdinalScript.getChampionWithOrdinal(1);
		local C2 = OrdinalScript.getChampionWithOrdinal(2);
		
		while (C2:getLevel() < C1:getLevel()) do
			C2:levelUp();
		end
	end
end
(not - tested)