Stack overflow error

Talk about creating Grimrock 1 levels and mods here. Warning: forum contains spoilers!
Post Reply
User avatar
LocalFire
Posts: 261
Joined: Thu Feb 21, 2013 1:16 am
Location: Auckland, New Zealand

Stack overflow error

Post 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?
My Dungeons
Paths of the Earth: viewtopic.php?f=14&t=5136
Beneath the Sands: viewtopic.php?f=14&t=5216
Videos: viewtopic.php?f=11&t=5443
User avatar
Xanathar
Posts: 629
Joined: Sun Apr 15, 2012 10:19 am
Location: Torino, Italy
Contact:

Re: Stack overflow error

Post 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)
Waking Violet (Steam, PS4, PSVita, Switch) : http://www.wakingviolet.com

The Sunset Gate [MOD]: viewtopic.php?f=14&t=5563

My preciousss: http://www.moonsharp.org
Post Reply