Author Topic: Key Find Help  (Read 3080 times)

Offline Mikewas

  • Mc. Print
  • *
  • Posts: 6
    • View Profile
Key Find Help
« 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
« Last Edit: 2010-Jul-14 by Mikeway »

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4143
  • On the shoulders of giants.
    • View Profile
    • My Apps
Re: Key Find Help
« Reply #1 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 :)
« Last Edit: 2010-Jul-14 by Ian Price »
I came. I saw. I played.

Offline Mikewas

  • Mc. Print
  • *
  • Posts: 6
    • View Profile
Re: Key Find Help
« Reply #2 on: 2010-Jul-14 »
Thank you i should have rememberd the while loop and i like let i looks more complicated with it

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Key Find Help
« Reply #3 on: 2010-Jul-19 »
Why do you need easy code that looks complicated?
The enduser won´t see your code  :P

Offline aonyn

  • Mr. Polyvector
  • ***
  • Posts: 136
    • View Profile
Re: Key Find Help
« Reply #4 on: 2010-Jul-20 »
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

Offline backslider

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 892
    • View Profile
Re: Key Find Help
« Reply #5 on: 2010-Jul-20 »
nice!   :help: :whip: