Page 1 of 2

Stack overflow error

Posted: Mon Sep 17, 2012 12:02 pm
by Lmaoboat
I keep getting "stack overflow underlining "for i=1,25 do", and I don't know why. It was working earlier, so I don't think it's related to what I'm doing with the code, so I think I must have put something a tab too far missed an end somewhere.

Code: Select all

function spawn()
	for i=1,25 do
		spawn("fx", 1, 5, 11, 3, "lcd"..i)
		local lcd = findEntity("lcd"..i)
		lcd:setLight(255,0,0,5,0.25, 360000, true)
	end
	
	
	lcd1:translate(-1,2.5,1.3)
	lcd2:translate(-0.5,2.5,1.3)
	lcd3:translate(0,2.5,1.3)
	lcd4:translate(0.5,2.5,1.3)
	lcd5:translate(1,2.5,1.3)
	lcd6:translate(-1,2,1.3)
	lcd7:translate(-0.5,2,1.3)
	lcd8:translate(0,2,1.3)
	lcd9:translate(0.5,2,1.3)
	lcd10:translate(1,2,1.3)
	lcd11:translate(-1,1.5,1.3)
	lcd12:translate(-0.5,1.5,1.3)
	lcd13:translate(0,1.5,1.3)
	lcd14:translate(0.5,1.5,1.3)
	lcd15:translate(1,1.5,1.3)
	lcd16:translate(-1,1,1.3)
	lcd17:translate(-0.5,1,1.3)
	lcd18:translate(0,1,1.3)
	lcd19:translate(0.5,1,1.3)
	lcd20:translate(1,1,1.3)
	lcd21:translate(-1,0.5,1.3)
	lcd22:translate(-0.5,0.5,1.3)
	lcd23:translate(0,0.5,1.3)
	lcd24:translate(0.5,0.5,1.3)
	lcd25:translate(1,0.5,1.3)
	
end



Re: Stack overflow error

Posted: Mon Sep 17, 2012 12:21 pm
by petri
You have an infinite recursion there (your are overriding the spawn function with your own).

Note that spawn() returns the created entity so you don't need to use findEntity() at all.

Re: Stack overflow error

Posted: Mon Sep 17, 2012 12:23 pm
by petri
Also please note that 25 dynamic light sources with shadow casting enabled will hurt the frame rate a lot on slower PCs.

Re: Stack overflow error

Posted: Mon Sep 17, 2012 12:24 pm
by petri
One more thing: r,g,b values are floats so they should be in range 0-1.

I'll shut up now :)

Re: Stack overflow error

Posted: Mon Sep 17, 2012 1:19 pm
by Komag
This LCD thing is shaping up to be pretty interesting!

Re: Stack overflow error

Posted: Mon Sep 17, 2012 7:40 pm
by Lmaoboat
Doh, seems so obvious now. I'l make sure to turn shadows off since they're not needed anyway.
Komag wrote:This LCD thing is shaping up to be pretty interesting!
Thanks. I can get the grid of dots working but setLight functions seem to add on top of themselves, so I make inverse of whatever was there before to turn them off instead of just setting everything to zero. Using timers and short durations is also tricky, because they gradually fade instead of just turning off after the duration is over.

Re: Stack overflow error

Posted: Mon Sep 17, 2012 8:17 pm
by Lmaoboat
Okay, now it's just crashing to desktop. I tried adjust how many tabs in some of the lines were, but that didn't seem to do anything.

Code: Select all

function light()
	for i=1,25 do
		spawn("fx", 1, 5, 11, 3, "lcd"..i)
			local lcd = findEntity("lcd"..i)
			lcd:setLight(1,0,0,5,0.25, 360000, true)
	end
	
	
	lcd1:translate(-1,2.5,1.3)
	lcd2:translate(-0.5,2.5,1.3)
	lcd3:translate(0,2.5,1.3)
	lcd4:translate(0.5,2.5,1.3)
	lcd5:translate(1,2.5,1.3)
	lcd6:translate(-1,2,1.3)
	lcd7:translate(-0.5,2,1.3)
	lcd8:translate(0,2,1.3)
	lcd9:translate(0.5,2,1.3)
	lcd10:translate(1,2,1.3)
	lcd11:translate(-1,1.5,1.3)
	lcd12:translate(-0.5,1.5,1.3)
	lcd13:translate(0,1.5,1.3)
	lcd14:translate(0.5,1.5,1.3)
	lcd15:translate(1,1.5,1.3)
	lcd16:translate(-1,1,1.3)
	lcd17:translate(-0.5,1,1.3)
	lcd18:translate(0,1,1.3)
	lcd19:translate(0.5,1,1.3)
	lcd20:translate(1,1,1.3)
	lcd21:translate(-1,0.5,1.3)
	lcd22:translate(-0.5,0.5,1.3)
	lcd23:translate(0,0.5,1.3)
	lcd24:translate(0.5,0.5,1.3)
	lcd25:translate(1,0.5,1.3)
	
end
EDIT:
Seem to have fixed it when I moved the translate entities around. Still not sure what it was though

Re: Stack overflow error

Posted: Mon Sep 17, 2012 9:27 pm
by antti
Lmaoboat wrote:I tried adjust how many tabs in some of the lines were, but that didn't seem to do anything.
Just for future reference, the tabs only serve to improve the readability of the code. The functionality is just the same with and without the indentation. It's definitely a good habit though.

Offtopic: writing about this reminded me of the only programming language that I know of which gives a damn about whitespaces: the aptly named whitespace. :D

Re: Stack overflow error

Posted: Mon Sep 17, 2012 9:29 pm
by Shroom
antti wrote: Offtopic: writing about this reminded me of the only programming language that I know of which gives a damn about whitespaces: the aptly named whitespace. :D
further off topic - python requires identation to work properly - god that bugs me :p

Re: Stack overflow error

Posted: Mon Sep 17, 2012 9:48 pm
by Lmaoboat
Finally figured out how to remove the lights to make place for a different number without having to have a specific one for each number. Changing the brightness or color would just add onto the current lights, but changing the duration doesn't.