GLBasic forum

Main forum => Tutorials => Topic started by: Mikewas on 2010-Jul-14

Title: Key Find Help
Post by: Mikewas on 2010-Jul-14
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
Title: Re: Key Find Help
Post by: Ian Price on 2010-Jul-14
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 :)
Title: Re: Key Find Help
Post by: Mikewas on 2010-Jul-14
Thank you i should have rememberd the while loop and i like let i looks more complicated with it
Title: Re: Key Find Help
Post by: backslider on 2010-Jul-19
Why do you need easy code that looks complicated?
The enduser won´t see your code  :P
Title: Re: Key Find Help
Post by: aonyn on 2010-Jul-20
If you want your code to look complicated, you'll  <3 this language.
http://en.wikipedia.org/wiki/Malbolge (http://en.wikipedia.org/wiki/Malbolge)   :S
Title: Re: Key Find Help
Post by: backslider on 2010-Jul-20
nice!   :help: :whip: