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 / Please help!!! UDTs, functions and global arrays...

Author
Message
skyser
22
Years of Service
User Offline
Joined: 11th Sep 2003
Location: New York, NY
Posted: 17th Sep 2003 05:05
Can someone please tell me if the following is possible? I can't seem to get my test code to work.

Say I have a UDT:

TYPE MyType
myField as INTEGER
ENDTYPE

I also have an init function to create a global array to be used to store a bunch of those types. I treat the array as a list later. The init function is called early in the program:

function init()
global dim myTypeList(0) as MyType
endfunction

Lastly, I want another function that can dynamically add a type to the list:

function newMyType()
m as MyType
array insert at top myTypeList(0)
myTypeList(1) = m
endfunction

The problem is that the array does seem to be growing, but I can't seem to access any of its contents by doing something like:
m2 as myType
m2 = myTypeList(0)
print str$(m2.ID)

Any ideas? Is this even possible? Is it a scoping problem because I'm creating the type var inside a function? Is it not possible to create UDT dynamically?

Would love you feedback, thanks!

--skyser
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 17th Sep 2003 09:59
Change the init code to be something like this:

Login to post a reply

Server time is: 2026-07-26 05:03:30
Your offset time is: 2026-07-26 05:03:30