second file in the IDE you can't set a value to a variable?!?!?!?

Previous topic - Next topic

Schranz0r

Hi buddys!


I have a problem with a second file in a project...
If i make this in the second file:

Code (glbasic) Select

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]
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Slydog

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:
Code (glbasic) Select
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:
Code (glbasic) Select
FUNCTION KeyStatus_Initialize:
KEY_SPACE.id = 57
KEY_1.id = 2
ENDFUNCTION

and call this from your main module before your loop.
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Schranz0r

thats the way!

THX!
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard

Slydog

Weird, no matter how I rearrange the code, I don't get that error.

To verify, here's what works for me:

KeyStatus.gbas:
Code (glbasic) Select
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:
Code (glbasic) Select
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
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Slydog

Ha, oops, great, you got it working, ignore that last message!
My current project (WIP) :: TwistedMaze <<  [Updated: 2015-11-25]

Schranz0r

hehe, put the id's in the functions works fine!
Thats the trick :)
I <3 DGArray's :D

PC:
AMD Ryzen 7 3800X 16@4.5GHz, 16GB Corsair Vengeance LPX DDR4-3200 RAM, ASUS Dual GeForce RTX™ 3060 OC Edition 12GB GDDR6, Windows 11 Pro 64Bit, MSi Tomahawk B350 Mainboard