Hi buddys!
I have a problem with a second file in a project...
If i make this in the second file:
GLOBAL bla
bla = 12
I get a error:
Quote"_keystatus.gbas"(43) error : command not inside function or sub
IT SUCKSSSSSSSSS!
Any walkaround to fix the problem?
If i put all this shit into a function i get this F***ING craaaaaappppppppppp :D :
Quote"_keystatus.gbas"(43) warning : variable already exists : KEY_SPACE
FFFFFFFFFFUUUUUUUUUUU :whistle:
I attach this shit ^^
[attachment deleted by admin]
You can only place code outside of a function in your main module ('KeyStatus.gbas' in your case).
In your other module ('_keystatus.gbas'), you have to move these lines:
KEY_SPACE.id = 57
KEY_1.id = 2
to the top of 'KeyStatus.gbas', above your WHILE loop.
Or, add an initialize function to the 2nd module:
FUNCTION KeyStatus_Initialize:
KEY_SPACE.id = 57
KEY_1.id = 2
ENDFUNCTION
and call this from your main module before your loop.
thats the way!
THX!
Weird, no matter how I rearrange the code, I don't get that error.
To verify, here's what works for me:
KeyStatus.gbas:
Initialize()
LOCAL counter%
WHILE TRUE
IF KEY_SPACE.onRelease() THEN INC counter, 1
IF KEY_SPACE.isDown() THEN PRINT "SPACE IS DOWN!", 10,20
IF KEY_SPACE.unpressed() THEN PRINT "Nothing happend on space!", 10,30
PRINT counter,10,10
SHOWSCREEN
WEND
END
_keystatus.gbas:
GLOBAL KEY_SPACE AS TKey
GLOBAL KEY_1 AS TKey
FUNCTION Initialize:
KEY_SPACE.id = 57
KEY_1.id = 2
ENDFUNCTION
TYPE TKey
id% // keyboardbutton ID
status% // 0 = nothing, 1 = down, -1 = released
ok% // if key is/was down
// if key is down return 1 else 0
FUNCTION isDown:
self.ok = KEY(self.id)
IF self.ok
self.status = 1
RETURN 1
ENDIF
RETURN 0
ENDFUNCTION
// on release of the button return 1 else 0
FUNCTION onRelease:
IF self.status = 1 AND self.isDown()= 0
self.status = -1
RETURN 1
ENDIF
RETURN 0
ENDFUNCTION
// if nothing is pressed it returns 1 else 0
FUNCTION unpressed:
IF self.isDown() = 0 AND self.onRelease() = 0
self.status = 0
RETURN 1
ENDIF
RETURN 0
ENDFUNCTION
ENDTYPE
Ha, oops, great, you got it working, ignore that last message!
hehe, put the id's in the functions works fine!
Thats the trick :)