Key Find Help

Previous topic - Next topic

Mikewas

it draws the sprite but the if will not work Basic is more confusing than c lol
I am gessing it is a simple mistake
Code (glbasic) Select
LOADSPRITE "bubble.png",0

LET x=250   
DRAWSPRITE 0,x,0
SHOWSCREEN

IF KEY (203) = 1
PRINT "key pressed", 20, 20
SHOWSCREEN
ENDIF


MOUSEWAIT
END

Ian Price

#1
There are a number of things wrong with your code -

1. You are not running the IF...ENDIF in a loop, so basically the code is only checking ONCE for the keypress and it occurs before you can even react!
2. You don't need SHOWSCREEN in the IF ... ENDIF
3. Place your SHOWSCREEN at the end of any loop
4. You don't need the "=1" after a keytest
5. You don't need LET
6. GLB is a LOT simpler than C, but just as powerful


Here is a working example of your code
Code (glbasic) Select


// Load sprite image
LOADSPRITE "bubble.png",0

// Loop this code until ESC pressed
WHILE TRUE

// Define variable X
x=250

// Draw image
DRAWSPRITE 0,x,0

// Print something if key pressed
IF KEY (203)
PRINT "key pressed", 20, 20
ENDIF

// Update screen
SHOWSCREEN

// End loop
WEND


Anyway, good luck and have fun :)
I came. I saw. I played.

Mikewas

Thank you i should have rememberd the while loop and i like let i looks more complicated with it

backslider

Why do you need easy code that looks complicated?
The enduser won´t see your code  :P

aonyn

If you want your code to look complicated, you'll  <3 this language.
http://en.wikipedia.org/wiki/Malbolge   :S
For by grace are ye saved through faith, and that not of yourselves: it is the gift of God: Not of works, lest any man should boast. -Ephesians 2:8-9

backslider