? A major problem. (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
Contest results!

A major problem.

  • #1 ✎ 109 Z_E_R_O Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself No matter what I try @MainLoop Vsync 1 bgclr cls Gosub @Player Gosub @Move Gosub @bg Gosub @BgCheck etc... and after a little while it will say "Stack Over Flow On line Whatever" Every stack overflow happens on my lines that have things to do with Gcirlcle Gcolor or bgfill, Bgcolor, Or anything like that. I've tried bgclr and everything nothing is working and I don't know why. I have used simiilar Mainloops in other games with no problem. Posted
  • #2 ✎ 1507 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS OSP Contest 2 Winner I won the second SmileBASIC Source OSP Contest! Programming Contest Second Year My account is over 2 years old Website Each time GOSUB runs, it adds 1 item to the stack, which keeps track of which spot in the program the GOSUB was called from. RETURN removes 1 item from the stack, and jumps to that location in the program. (Other things use the stack as well, but I'm pretty sure GOSUB is the problem here) If you use GOSUB too many times without RETURNing, the stack will fill up and you'll get a stack overflow error. If the stack is almost full, other actions can cause a stack overflow too, like calling functions or creating arrays. Posted Edited by 12Me21
  • #3 ✎ 109 Z_E_R_O Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself
    Each time GOSUB runs, it adds 1 item to the stack, which keeps track of which spot in the program the GOSUB was called from. RETURN removes 1 item from the stack, and jumps to that location in the program. If you use GOSUB too many times without RETURNing, the stack will fill up and you'll get a stack overflow error.
    I have it set to where it goes to a loop @A1 Gosub @Mainloop Goto @A1 It returns there from the mainloop everywhere I have set to Gosub, I have it set to return and for some reason it still stack overflows... :(
    Posted
  • #4 ✎ 1507 12Me21 Admin Syntax Highlighter Received for creating the code syntax highlighter on SBS OSP Contest 2 Winner I won the second SmileBASIC Source OSP Contest! Programming Contest Second Year My account is over 2 years old Website Try commenting out some of your GOSUBs to find which one is causing it. It's probably just a typo or something. Make sure you don't use GOTO to exit from a GOSUB: GOSUB @EXAMPLE @BAD END @EXAMPLE GOTO @BAD 'don't skip the RETURN like this RETURN Posted
  • #5 ✎ 109 Z_E_R_O Intermediate Programmer I can make programs, but I still have trouble here and there. Programming Strength Night Person I like the quiet night and sleep late. Express Yourself Zelda Is Awesome! I love The Legend Of Zelda! Express Yourself @bg it tells it if it's in a certain place to go to a border liike this if p==1 the gosub @Border1 Gosub @border2 @border1 for I=1 to 23 if rnd(99)==1 then wbg=wbg+.1 if wbg>149.9 then wbg=147 bgfill 1,18,1,7,5,wbg bgput 1,I,0,102 next return Thats one of the ones that causes an overflow then another one is @Bgg Bgfill 0,1,1,23,13,bg return and then randomly it will do it because of bgcircle. Posted
  • #6 ✎ 60 seggiepants It sounds like you have a case of Spaghetti code. This sort of thing is why I suggest using functions and while/repeat loops over gosub and goto. Goto generates this sort of problem rather easily. You are calling gosub without returning and eventually you run out of stack space. It runs ok for a little while then fails randomly right? For example in your previous post you have code that jumps to @border1 if p equals 1, but after that it will continue on and run through @border2, and finally run through @border1 again since nothing ever sent it back home. Is that really what you want it to do? If you want to post a key maybe I can try rewriting it to get rid of some of the bugs (although if I did it, my modified version would be full of functions and loops not goto/gosub). Posted