I'm using user-defined types for handling my variables, but it seems they are having a problem going global.
I am using my Types as arrays - for simplified version of the code that isn't working:
in source.dba
Type Character
MaxHP as integer
HP as integer
MaxMP as integer
MP as integer
endtype
sync on
sync rate 60
global player = 1
global enemy = 2
dim Cha(2) as Character
SetUpCharacter()
Start:
do
if inkey$() = "i" then Menu()
sync
loop
Characters.dba
function setUpCharacter()
cha(player).MaxHP = 400
cha(player).MaxMP = 400
cha(player).HP = cha(player).maxHP
cha(player).MP = cha(player).maxMP
endfunction
Menu.dba
function Menu()
do
text 0, 10, "HP: " + str$(cha(player).HP)
text 0, 20, "MP: " + str$(cha(player).MP)
if spacekey() =1 then goto start
sync
loop
endfunction
When I hit 'i' to call the menu, the variables display as '0' instead of the ones I've defined (even in the above simplification). I've tried setting all of the data as globals inside of the types, like 'Global MaxHP as integer' and globalising the array declaration 'global dim cha(2)', but they don't work. I can't globalising each variable like, 'global cha(player).MaxHP'. When the Text commands are called inside of the loop in source.dba then the data displayed is correct but when called in an outside function it isn't.
So, I'm a little stumped as to how to fix this.