Can someone help me? It does a stack overflow on line 345 after a while of running the program. It would be nice if someone would help:) (and no mean criticism)
Can you upload it and provide the key? I'm guessing your code is leaving the GOSUB by means other than RETURN, but it's hard to tell from just a short snippet.
I had another variable named "S" so that might have been the problem. But... just as soon as I may have fixed that, it said a stack overflow happened in line 240. Can somebody tell me how to fix that? And I wont upload the key until the games done.
GOSUB stores the "from" address on the stack and adjusts the stack pointer. RETURN retrieves that address from the stack and adjusts the stack pointer back to what it was.
If a program's flow causes it to use GOSUB without matching RETURN statements, eventually the stack's memory will be full and an error will occur. Similarly, if a program's flow causes it to use more RETURN than GOSUB statements, RETURN will attempt to access memory outside of that allocated to the stack, resulting in an error.
Check that every time your program enters a subroutine through a GOSUB it always exits through a RETURN. Also check that your program never enters a subroutine other than through a GOSUB if it must exit through a RETURN.
Well I have these power ups in my game and when you hit one it makes you GOSUB to another area of code, but the thing is I have off branches of GOSUBS in the power ups code so I can't use return to go back to my original loop. instead, when it senses a collision it GOSUBS back to @9 which is before my main loop and then enters the main loop which uses WHILE and WEND to repeat. :O so what do I do?
Really, thats interesting :) maybe I'll look at that too. the only thing is, I have a ton of GOSUBS and wouldn't want to replace every single one with GOTOS.
I'm sorry for lack of my previous explanations. As everyone has already said, GOTO and GOSUB are completely different and the GOSUB without RETURN wastes stacks.
@IOIOOIOOI, but most of my gosubs are under certain conditions and do not return quickly... I trying to change a little of my code right now, I'll let you know how it goes.
GOSUBS don't have to RETURN immediately. You could do something like this:
GOSUB @LOOPY
@LOOPY
DO STUFF
IF THING == TRUE THEN RETURN
GOTO @LOOPY
Once you want to return to the original loop, make THING = TRUE and then it will return; otherwise it will stay in the loop you want it to. That said, it would probably just be best to GOTO your other loops, and then GOTO back to your main...
I changed a lot of my code to GOTOS instead of GOSUBS and IT WORKED (for now ;) thank you everyone for your patience, help, and comments :) now I can get to 40000 without having a stack overflow Yaaaaaaaah!!!
You can edit code shorter.For example,
==
IF SPHITSP(5, 4)>0 OR SPHITSP(5,15)>0 OR SPHITSP(5,16)>0 OR SPHITSP(5,18)>0 OR SPHITSP(5,20)>0 THEN GOSUB @DEAD
IF SPHITSP(5,51)>0 THEN
SPSET 5,16:SPSET 1,17:SPSET 2,18:SPSET 3,19
SPSCALE 5,2,2
ENDIF
==
If you'vs already used SPSET to same Sprite Number,you have to use SPCHR instead of SPSET.
Just an advice, if you have trouble tracing your program properly, then you may want to redesign it, or else you may end up with spaghetti code. In your case, you may want to try to flatten it so that you don't have to use GOTO/GOSUB so much.
Yah, well I already have so much code done and I don't really want to change anything :) (did anybody know this is my first official game I have ever made. And it is awsome. I LOVE YOU SMILEBASIC! )