Just follow the flow of the code. Try to read it and do what the computer would do if you pressed the rightkey. It's what i use to help me debug my code. I will show you.
Lets say that the rightkey was pressed since this is the case when the bug occours. so lets look at the first part of that code
if rightkey()=1 and starshipX < 540
hide sprite starship
show sprite starshipright
inc starshipX,6
else
hide sprite starshipright
show sprite starship
endif
Since rightkey=1 we hide the sprite starship and show the sprite shipright.
This part is working just fine. Lets take a look at the second part.
if leftkey()=1 and starshipX > 2
hide sprite starship
show sprite starshipleft
dec starshipX,6
else
hide sprite starshipleft
show sprite starship
endif
Well the left key isin't pressed so we do the else action
hide sprite shipleft show sprite starship
Do you see what is wrong now?
Since the left key isint pressed the sprite starship is shown.
To fix this I would just combine the 2 if else statements into one if else if else if statement like this
if rightkey()=1 and starshipX < 540
hide sprite starship
hide sprite starshipleft
show sprite starshipright
inc starshipX,6
else
if leftkey()=1 and starshipX > 2
hide sprite starship
show sprite starshipleft
hide sprite starshipright
dec starshipX,6
else
hide sprite starshipleft
hide sprite starshipright
show sprite starship
endif
endif
I just moved the hide sprite shipright to the bottom else statement so I could delete the else statement below the if rightkey()=1 statement. I deleted the else statement from it, but i dont want to close the if statement just yet so we move the endif statement down with the other one. When we do it this way if you change from rightkey to left key without depressing both keys then the sprite shipright wont get hidden, so I added that to both the if leftkey()=1 statement. I did the same with the if rightkey()=1 statement for the shipleft sprite.
If you press both right and left keys it will display the shipleft sprite but the ship will move right then left. If you are useing manual syncing then the ship will stay in its same spot but will show the shipleft sprite. We can solve this by adding in another if statement below the one we have. The statement would look something like this:
if rightkey()=1 and leftkey()=1
hide sprite starshipleft
hide sprite starshipright
show sprite starship
endif
Hope all this made sense, and you understand it if it did.
When life hands you lemons go buy some oranges to make orange juice, and stop expecting everything to be given to you.