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 / Updating TYPE'd variables in functions

Author
Message
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 19th Oct 2010 12:07
I am trying to create a function to deal with a TYPE'd variable.

It appears that functions in DB Pro only pass by value, you cannot get a pointer to a user-defined TYPE and you cannot return a user-defined TYPE.

How are generic functions meant to be written if the contents of a TYPE cannot, in any way, be updated by the functionality within the function?
Van B
Moderator
23
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 19th Oct 2010 13:35
You would have to use globalised typed variables, or pass a reference to a typed array, like passing the ID of the array and updating the typed values inside the function.

Would be great if we could use types explicitly in functions, but there is no technique for that, although I might be wrong, maybe someone wrote a plugin to add extra types support. I often keep a global variable for each type, for use as a buffer, or for returning values set inside the function.

Health, Ammo, and bacon and eggs!
bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 20th Oct 2010 09:04
It is most frustrating that the basic concepts of a language are not available. Utilising a global variable entails that the function cannot be generic; ie. you have a function dealing with manipulating an enemy sprite, by using globals within the function is cannot be generic...

Following on from the suggestion of an array with the position within that array passed in as the parameter; does this entail that there is any way of dynamically allocating the size of an array?
Neco
18
Years of Service
User Offline
Joined: 13th Jul 2008
Location: Waterloo, Wisconsin USA
Posted: 20th Oct 2010 17:43 Edited at: 20th Oct 2010 17:44
You can DIM an array as empty



And you can dynamically insert objects into the array



This should be covered in the help files (Help->Principals->Lists, Stacks, Queues) So you can insert and remove items in various ways.

A standard list, or a Stack (FILO) or Queue (FIFO)

bodmcn
15
Years of Service
User Offline
Joined: 6th Oct 2010
Location:
Posted: 21st Oct 2010 05:37
Many thanks

I missed that section, d'oh. Good to know

I have changed the code over to global arrays with the positional value passed in as parameters. Many thanks for you suggestion.
Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 21st Oct 2010 11:32
I usually do something like this:



or,


that is, where callFunction() has a syntax exactly like the 3dmaths vector/matrix commands.

Login to post a reply

Server time is: 2026-07-22 03:51:49
Your offset time is: 2026-07-22 03:51:49