Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Types/Arrays not Going Global?

Author
Message
Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 14th Feb 2012 15:41 Edited at: 14th Feb 2012 16:25
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



Characters.dba


Menu.dba


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.
Brendy boy
20
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 14th Feb 2012 15:50
instead of this

do this


There's been a thread exactly about this few days ago!!

Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 14th Feb 2012 16:49 Edited at: 14th Feb 2012 17:00
I'm an idiot. But thank you.

I'm an idiot because the reason the 'simplified' version didn't work was being in 'Menu.dba' I used 'Keats' as a variable instead of 'player' as was defined in that sample. ('Keats' is the name I'm using in my actual project).

The other reason I'm an idiot:

There's a variable called cha(keats).path.whisperer, which if set to '1' gives the player a different set of stats. And I placed 'cha(keats.path.whisperer) = 1' AFTER the Player functions are called, hence why it wasn't working.



I hate it when it's something so simple you just overlook it completely.


Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 15th Feb 2012 02:58
You had me worried there, I thought it was strange that your code did not work; it worked fine on my machine.

Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 19th Feb 2012 23:35 Edited at: 19th Feb 2012 23:35
@Seppuku Arts: also i would suggest to define each format you using
global MyStr as String
global MyInt as Integer
global MyBol as Boolean
etc.

this will make you read easy. and less bugs dbp will show..

[edit]
whats up dude? long time no see

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 19th Feb 2012 23:54
Cheers for the hint. My labels weren't the problem, just my stupidity in placing variable declarations after a function instead of before. I settled down with labels that should make sense in that you can tell .name & .filename are strings, .HP and .MP are integers and .exist and .whisperer (the name of the character's class) are booleans.

Cha(keats).path.whisperer = 1 reads as "Character, Keats, his whisperer path is active"

And yes, not seen you on here for years.


Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 20th Feb 2012 00:13
u still use ur old msn? cuz i cant find u on it..
could u add me?

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
Sergey K
22
Years of Service
User Offline
Joined: 4th Jan 2004
Location:
Posted: 20th Feb 2012 00:37


try to sort the code that way..

and i dont see any problem with that..
it should work fine..

more 3d models .x/.obj and more foramts here:
[href]https://www.turbosquid.com/Search/Index.cfm?keyword=gogetax1&x=0&y=0[href]
Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 20th Feb 2012 01:20
That's a simplified version of what I've actually got, but yeah, that's pretty much how I've kept it structured, just with more. Fixing bugs has been a lot easier than previous methods I've used for managing my code. The original source was a mess compared to this, hence I changed it.


Gunslinger
19
Years of Service
User Offline
Joined: 29th May 2007
Location:
Posted: 20th Feb 2012 03:14
Well, i got some problems with global types.

If i got something like
main.dba
bla.dba
bla2.dba

and i put that
type caracter
...
endtype
global dim characters(999) as character
into bla.dba, i cant call it from bla2.dba. I have to put it in the main.dba to work. Is that normal? :S
Dreq934
22
Years of Service
User Offline
Joined: 15th Dec 2003
Location: SC, USA
Posted: 20th Feb 2012 08:29 Edited at: 20th Feb 2012 08:32
I simply have a GlobalDefinitions.dba file that is a single Function block full of Global variable initialization. It gets called right off the bat in the main file, at which point all other files seem to have no problems accessing or changing them.



I believe doing it inside of a function call, then calling said function on the first line of the main file forces DBP to initialize those globals, regardless of the order things are done in.

Dark Basic Professional
Seppuku Arts
Moderator
21
Years of Service
User Offline
Joined: 18th Aug 2004
Location: Cambridgeshire, England
Posted: 20th Feb 2012 11:48
Quote: "into bla.dba, i cant call it from bla2.dba. I have to put it in the main.dba to work. Is that normal? :S"


I've tried making UDT's in a function in a separate file but I haven't found that works either. All my UDT's are defined right at the start of the program in the main source file, if you run something like Indigo you should be able to collapse all of the types at the top if they're in the way (which may be the case if you've got lots of types)


MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 20th Feb 2012 21:47
Dreq934

hit on my question... will this work in urm Synergy?

Login to post a reply

Server time is: 2026-07-09 17:43:06
Your offset time is: 2026-07-09 17:43:06