Function Switching Bug
Root / Programming Questions / [.]
randoCreated:
I am working on bottom screen functions for a game. I have 2 right now, a menu and a world manipulator. Basically the menu switches between functions; the world editor, map, player inventory, etc. When I switch to the world editor, it works, then I go back to the main menu. From there I can't go back to the world editor. I don't know why. Here are some code screenshots to help anyone understand what's going on:
That's the function runner.
That's the bottom screen menu.
That's the world editor.
The world editor isn't finished, clearly, because it doesn't edit anything other than whether or not it's in the editor.
Anyway, I don't understand why this bug occurs. Any help would be appreciated.
Also, please note that some of these screenshots overlap.
Ok, this is really weird. When I switched the SPHITSP(0) to SPHITSP(0,4,10) in BMENU() it worked. I don't exactly know what's going on, if anyone who does would care to explain that would be nice.The problem with this code is that sprite 0 might be colliding with multiple sprites, in which case SPHITSP(0) is only giving you the first sprite being collided with. To get the rest of the sprites being collided with, you have to call SPHITSP() without any parameters until you get -1. (Unfortunately, SPHITSP() without parameters isn't documented on the English reference page for SB3, though it is on the Japanese reference page and in the English in-game help.) You have code in BMENU that looks like this:
HIT=SPHITSP(0) IF HIT==4 THEN SPCLR RETURN 1 ELSE RETURN 0 ENDIFInstead, this code needs to look something like this:
HIT=SPHITSP(0) WHILE HIT>=0 IF HIT==4 THEN SPCLR RETURN 1 ENDIF 'Get the next sprite being collided with HIT=SPHITSP() WEND 'If we haven't returned 1 already, we aren't colliding with sprite 4, so... RETURN 0
This makes sense. Maybe what was happening was in BMENU() SPCOL wasn't used on the sprite behind sprite 4. Then TOPLACE() used SPCOL on that sprite and it still took effect. I'm not sure, but that might be the cause of the bug. So even though the bug is already fixed, I'll update to what you put because of efficiency and stuff. Also, for anyone wanting a key, I will put it up when it's finished. It might be a few days.Ok, this is really weird. When I switched the SPHITSP(0) to SPHITSP(0,4,10) in BMENU() it worked. I don't exactly know what's going on, if anyone who does would care to explain that would be nice.The problem with this code is that sprite 0 might be colliding with multiple sprites, in which case SPHITSP(0) is only giving you the first sprite being collided with. To get the rest of the sprites being collided with, you have to call SPHITSP() without any parameters until you get -1. (Unfortunately, SPHITSP() without parameters isn't documented on the English reference page for SB3, though it is on the Japanese reference page and in the English in-game help.) You have code in BMENU that looks like this:HIT=SPHITSP(0) IF HIT==4 THEN SPCLR RETURN 1 ELSE RETURN 0 ENDIFInstead, this code needs to look something like this:HIT=SPHITSP(0) WHILE HIT>=0 IF HIT==4 THEN SPCLR RETURN 1 ENDIF 'Get the next sprite being collided with HIT=SPHITSP() WEND 'If we haven't returned 1 already, we aren't colliding with sprite 4, so... RETURN 0