LoginLogin

spused problem

Root / Programming Questions / [.]

randoCreated:
before any objections, i didnt find ANYTHING here or on the web. guess not much people use spused. anyway, i have a program im making(programming contest) and i have it so the enemy sprite moves if it exists, with
g=spused(1)
 if g==false then return
. it wont work right, until i make the player jump. please help!

SPUSED(1) becomes true as soon as you create it with SPSET 1,..., and becomes false when it's deleted with SPCLR 1, so I'm not sure why jumping should affect that. You say it doesn't work right, but what exactly happens? Does the enemy not spawn until you jump? Does it spawn, but just stays in place until you jump?

it spawns, but even though i have it a moving code in the main loop, it wont move unless i jump. its kinda like this: while mydead==0 spset 0,0 stick out sx,sy x=x+sxยค2 spofs 0,x,y gosub@jump gosub@enemygen gosub@enemymove gosub@collision wait 2 wend @jump if button(0)!=16 then return repeat dec y wait 1 until button(0)!=16 return @enemygen a=rnd(3) if a==0 then a=1 if a==1 then a=2 if a==2 then a=3 if a==3 then a=4 spset 1,a return @enemymove a=spused(1) if a==false then return and the rest of this. idk why it doesnt work. this is why i needed help.

I'm a bit confused because as far as I can tell from this code, it should only be moving when you're not jumping. That is a problem with this code nevertheless, though, so I'll explain why it does that, in case it has something to do with your actual problem. You have a WAIT loop in your @JUMP routine. The problem with this is that while it's waiting in @JUMP, it can't do anything else, including update enemies. In other words, this is how your code works:
Frame 0:
 run main loop
  run jump code
   button is not pressed, so return
  run enemy gen
  run enemy move
  run collision
  wait 2 frames

Frame 2:
 run main loop
  run jump code
   button is not pressed, so return
  run enemy gen
  run enemy move
  run collision
  wait 2 frames

Frame 4:
 run main loop
  run jump code
   button is pressed, so run jumping loop
    wait 1 frame

Frame 5:
   button is pressed, so run jumping loop
    wait 1 frame

Frame 6:
   button is pressed, so run jumping loop
    wait 1 frame

Frame 7:
   button is pressed, so run jumping loop
    wait 1 frame

Frame 8:
   button is not pressed, so return
  run enemy gen
  run enemy move
  run collision
  wait 2 frames

Frame 10:
 run main loop
  run jump code
   button is not pressed, so return
  run enemy gen
  run enemy move
  run collision
  wait 2 frames
Notice how as long as that button is pressed down, it does nothing but wait in that loop. Because SmileBASIC can only do one thing at a time, you have to avoid routines that span over multiple frames like that. Something that would work is simply:
@jump
if button(0)!=16 then return
dec y,2
return
This would only update once every two frames though, but that's more consistent with the rest of your code anyway.