? Bullet won't move along y-axis (Page 1) ● SmileBASIC Source Forums

Sign In

Register
*Usernames are case-sensitive
Forgot my password
This website has been moved, please see this post

Bullet won't move along y-axis

  • #1 ✎ 8 iwantham Hi, 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 Posted
  • #2 ✎ 120 kitesinpowerlines Avatar Block I didn't change my avatar for 30 days. Website Avatar Embargo I didn't change my avatar for 90 days Website Avatar Taboo I didn't change my avatar for 180 days Website 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. Posted
  • #3 ✎ 1884 12Me21 Syntax Highlighter Received for creating the code syntax highlighter on SBS Night Person I like the quiet night and sleep late. Express Yourself You used OUT BUPY instead of OUT X,Y in BULLETFUNC Posted Edited by 12Me21
  • #4 ✎ 8 iwantham
    You used OUT BUPY instead of OUT X,Y in BULLETFUNC
    I switched it out and it still has the same issue.
    Posted
  • #5 ✎ 8 iwantham
    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...
    Posted
  • #6 ✎ 212 seggiepants I think you are missing a call to CALL SPRITE in your game loop Posted
  • #7 ✎ 8 iwantham
    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...
    Posted Edited by iwantham
  • #8 ✎ 18 Na_trium SPFUNC 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. Posted
  • #9 ✎ 212 seggiepants call 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. Posted