#1✎ 8iwanthamHi, I'm having an issue where when bullets are created on my player sprite, instead of going up the y-axis they just spawn and sit still. My code was taken from this guide (https://smilebasicsource.com/page?pid=982) but modified, as my bullets only need to be sent upwards.
Here's my code.
I think there's something funky going on with my BulletFunc function but I'm not sure. Everything seems to work up until the point where it needs to update the y-axis position for the bullet. Or maybe it has to do with the syntax at the end of the BulletFunc.
Any suggestions? I just started coding today so it's pretty messy looking I'm sure
#2✎ 120kitesinpowerlinesAvatar BlockI didn't change my avatar for 30 days.WebsiteAvatar EmbargoI didn't change my avatar for 90 daysWebsiteAvatar TabooI didn't change my avatar for 180 daysWebsiteIt looks like you use global variables X and Y for player movement and as local variables in the BULLETFUNC function. The bullet sprite may be getting confused and sticking with the global Y variable for your player. Try changing the variable names in your BULLETFUNC to something more unique and see how that goes.
#3✎ 188412Me21Syntax HighlighterReceived for creating the code syntax highlighter on SBSNight PersonI like the quiet night and sleep late.Express YourselfYou used OUT BUPY instead of OUT X,Y in BULLETFUNC
It looks like you use global variables X and Y for player movement and as local variables in the BULLETFUNC function. The bullet sprite may be getting confused and sticking with the global Y variable for your player. Try changing the variable names in your BULLETFUNC to something more unique and see how that goes.
Tried renaming the local variables and it does the same thing. Very odd, I'm tempted to just rewrite the entire thing but I am very curious what I missed...
#6✎ 212seggiepantsI think you are missing a call to CALL SPRITE in your game loop
I think you are missing a call to CALL SPRITE in your game loop
if button(1,B#_RDOWN)==1 then makebullet x,y
I think this calls the sprite, and besides the bullet spawns, it just doesn't move.
EDIT you are correct, in the guide I read there was a call sprite but I can't find where he named that variable so I'm unsure what to do in mine...
#8✎ 18Na_triumSPFUNC NSP,"BULLETFUNC" sets the function BULLETFUNC to the sprite so that BULLETFUNC will be called on CALL SPRITE.
"CALL SPRITE" is one command and SPRITE is not a variable.
#9✎ 212seggiepantscall sprite is a command that tells smilebasic to call the functions you set up with spfunc (which you set up in MAKEBULLET).
It calls your callback function for a sprite passing in the id number through the global CALLIDX.
That is why your bullet doesn't move because you need to tell smilebasic to call the sprite functions once a frame.
call and sprite are both keywords here and not variables but I can see how it would be confusing.
all you have to do is add call sprite to your main game loop.