TGC Codebase Backup



Non by DMM

30th Sep 2008 21:27
Summary

Got tired of using the wait delay to avoid repeated actions during a key press. This function takes a key input (here its the spacekey()) and returns true only if its been released



Description



Code
                                    ` This code was downloaded from The Game Creators
                                    ` It is reproduced here with full permission
                                    ` http://www.thegamecreators.com
                                    
                                    `/////////////////////////////////////////////

` Done with some help from Skyser's (at Electronic Funstuff) double-click detection code

`/////////////////////////////////////////////


global isbtndown as integer = 0
global pressedCode as integer = 0

do
if checkSpacebar() = 1
   print "do whatever it is you want to happen when the spacebar is pressed in this line"
endif
if (escapekey() = 1) then exit
loop




function checkSpacebar()
     pressedCode = spacekey()
     if (pressedCode <> 1) and (isbtndown = 0) then exitfunction 0

     select pressedCode

     case 0:
          if isbtndown = 1 then isbtndown = 0
          exitfunction 1
     : endcase

     case 1:
          isbtndown = 1
          exitfunction 0
     : endcase

     endselect
endfunction 0