Also if you can work out where the problem is coming from post that block of code instead of the whole program
I've taken a look at your code and your hp variable prints fine, it prints so well it goes right off the bottom of the screen

but then others have already explained what to do about that
I've played around with your controls a bit to condense your code; you were checking for the same thing over and over which usually means you can do it a better way.
l=leftkey() : r=rightkey()
if l+r = 1 :`if either leftkey or rightkey is pressed (not both)
spritex=spritex+(r*2)-(l*2) : `move horizontally
if sprite mirrored(1) = r then mirror sprite(1) : `mirror
if timecounter = 0
inc framenumber,1 : if framenumber >6 then framenumber = 2 :`animate
endif
else
framenumber = 1 :`reset animation
endif
I will explain what I've done, maybe some of the ideas will be useful to you in the future.
Firstly I made two variables to store the leftkey() and rightkey()
l=leftkey() : r=rightkey()
I like to store inputs in variables for two reasons:
A. It's quicker to type.
B. They are stable for the entire loop or until you look at the inputs again.
Being able to think about inputs as just another set of numbers will help you to use maths to great effect in your programs.
The most significant modification I made was putting both left and right movement into the same block. At first it doesn't look like you can do this because they do the opposite, but if we use the left and right variables themselves we can condense it all into the same block of code. The movement code is a good example of this
spritex=spritex+(r*2)-(l*2) : `move horizontally
If rightkey is pressed then r=1 and 1*2 is 2, so by adding 2 to the sprite position we are moving it right, and it's exactly the same for left except we are subtracting the result.
In order to mirror the sprite so that it's facing the correct way, we again need to think of our inputs as numbers.
I haven't seen your image but I'm going to assume that link is facing right; so if we are moving right we don't want our sprite to be mirrored (sprite mirrored(1)=0 is want we want). So obviously if we are moving left we want our sprite to be mirrored so it faces left (sprite mirrored(1)=1).
A simple way to do this would be:
if r=1 and sprite mirrored(1)=1 then mirror sprite 1
if l=1 and sprite mirrored(1)=0 then mirror sprite 1
but we have this opposite thing again between left and right.
r seems to be the most important of the two here: when r=1 if sprite mirrored()=1 (the same as r) we need to mirror the sprite, also (assuming that when l=1 r=0) if r=0 and sprite mirrored()=0 (same as r) we need to mirror the sprite.
So we can make a simple equation based on r:
if sprite mirrored(1) = r then mirror sprite 1 : `mirror
I think I've explained that in a very complicated way but hopefully the equation makes sense.
The final thing I did was add in the reset animation line into the block. This is what ELSE is for:
if l+r = 1 :`if either leftkey or rightkey is pressed (not both)
`true code here
else
framenumber = 1 :`reset animation
endif
I hope that was of use to you