プレイ日記
Josiah Spike4
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)
7そうだね
プレイ済み
返信[1]
親投稿
Josiah Spike4
I mean line 349. Sorry :/
0そうだね
プレイ済み
返信[2]
親投稿
Cris cmart592
Check if you have already used the variable, try switching the two numbers for the sphitsp, and also change s>0 to something...
0そうだね
プレイ済み
返信[3]
親投稿
OlOOlOOl pi_r_round
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.
1そうだね
プレイ済み
返信[4]
親投稿
Josiah Spike4
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.
0そうだね
プレイ済み
返信[5]
親投稿
OlOOlOOl pi_r_round
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.
0そうだね
プレイ済み
返信[6]
親投稿
OlOOlOOl pi_r_round
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.
0そうだね
プレイ済み
返信[7]
親投稿
OlOOlOOl pi_r_round
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.
0そうだね
プレイ済み
返信[8]
親投稿
TN21 Trinitro21
Try using GOTO instead of GOSUB.
0そうだね
プレイ済み
返信[9]
親投稿
Josiah Spike4
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?
0そうだね
プレイ済み
返信[10]
親投稿
Josiah Spike4
aren't GOTO and GOSUB the same?
0そうだね
プレイ済み
返信[11]
親投稿
TN21 Trinitro21
No. You can't return from a GOTO but GOTO can't produce stack overflows.
0そうだね
プレイ済み
返信[12]
親投稿
TN21 Trinitro21
Just don't nest more than ~16000 of them.
0そうだね
プレイ済み
返信[13]
親投稿
TN21 Trinitro21
*GOSUBs I mean
0そうだね
プレイ済み
返信[14]
親投稿
Josiah Spike4
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.
0そうだね
プレイ済み
返信[15]
親投稿
Hanzo rzsense
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.
0そうだね
未プレイ
返信[16]
親投稿
OlOOlOOl pi_r_round
If organized properly, you can GOSUB within a GOSUB then RETURN to a RETURN to get back to the original calling code.
0そうだね
プレイ済み
返信[17]
親投稿
OlOOlOOl pi_r_round
(forgot the screen shot of code that illustrates this)
0そうだね
プレイ済み
返信[18]
親投稿
Josiah Spike4
@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.
0そうだね
プレイ済み
返信[19]
親投稿
mystman12 mystman12
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...
0そうだね
プレイ済み
返信[20]
親投稿
mystman12 mystman12
loop once you want to, like this: @LOOP IF YOU WANT TO GOTO @LOOPY GOTO @LOOP @LOOPY DO STUFF IF THING == TRUE THEN GOTO @LOOP GOTO @LOOPY
0そうだね
プレイ済み
返信[21]
親投稿
Josiah Spike4
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!!!
2そうだね
プレイ済み
返信[22]
親投稿
Cris cmart592
Yayayayayyayayay!
0そうだね
プレイ済み
返信[23]
親投稿
こうやま kouyama1435
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.
0そうだね
未プレイ
返信[24]
親投稿
Hanzo rzsense
I'm glad that it has been resolved by yourself. I cannot wait the release!
0そうだね
未プレイ
返信[25]
親投稿
ĦHarry Ramstrong
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.
0そうだね
プレイ済み
返信[26]
親投稿
Josiah Spike4
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! )
0そうだね
プレイ済み