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 / Data types and Arrays

Author
Message
SasukiShinozawa
23
Years of Service
User Offline
Joined: 11th Feb 2003
Location:
Posted: 18th Feb 2003 00:22
Is it possible to make arrays of your own data types? I've been trying this

type Button
left as integer
right as integer
bottom as integer
top as integer
active as integer
endtype

When I try to do this:

Global Buttons(4) as Button

I get an error about not being able to compile on the line two lines above this code. The only other things in my program are

hide mouse
autocam off
sync on
sync rate 60

So what's wrong here? Thanx a lot if you can help.
Tanto? Iie. Kore wa tachi desu.
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 18th Feb 2003 00:29
just use

dim buttons(4) as button

it appears that arrays are automatically Global so you can't / don't need to use the global command.

You can definately make arrays of User Defined Types though, I use them for level object in my projects.

NOBODY has a forum name as stupid as Darth Shader. I do.
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 18th Feb 2003 01:33
array's are global when outside of functions, and when they're UDT'd (^_^)

if within a function and only want then in the function then you have to local them...

[name]() usually stands for an array, which must be declared with the "dim" (declare in memory) command prior to use - else Pro will go "WTF is this!?"



as your not declaring the types within the array but the possible instances of them then the array above gives you 255 buttons

and it is always good to optimised the setup of your data, as it isn't likely your screen width or screen height will ever exceed 65535 x 65535 there is no need to declare as integers - even if it does i'd suggest a dword, because screen sizes are never below 0

also i placed active as a boolean because that is either 1 yes it is or 0 no it isn't - means you can setup


then use TRUE and FALSE instead

lastly the useage is

if arButton(1).active = TRUE then dofunction()

with dofunction() as whatever you want it to do, but thats basically how you use the types... the more types attached the more (.) subs

for example


thats completely random but you get the idea

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 18th Feb 2003 01:38
oh and i usually add _t on the end of types to make sure that the type names don't collide with variable names, you don't have to do this ... just a common practise, like when i declare variable i add on the front they're type



(^_^) not nessary it just is good practise to remember what values are needed when

Tsu'va Oni Ni Jyuuko Fiori Sei Tau!
One block follows the suit ... the whole suit of blocks is the path ... what have you found?
SasukiShinozawa
23
Years of Service
User Offline
Joined: 11th Feb 2003
Location:
Posted: 18th Feb 2003 01:57
Yeah, I usually add some sort of mnemonics device for things like that. Thanx guys!

Tanto? Iie. Kore wa tachi desu.

Login to post a reply

Server time is: 2026-07-21 14:40:48
Your offset time is: 2026-07-21 14:40:48