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 / Passing a List as a Parameter Question

Author
Message
His Imperial Majesty
18
Years of Service
User Offline
Joined: 19th Sep 2007
Location: Throne World of Korhal
Posted: 10th Jun 2011 06:23
Hi all,

I just had a quick question about passing a list as a parameter in a user-defined function.

I was wondering if some variation of this is possible:



I've tried the above and it doesn't work but what I'm wondering is if there's any way to create an instance of a list while passing it as a parameter? I'd like to be able to pass just a bunch of strings or other data types and have them be interpreted as a string.

I know such functionality exists in Python and Java so I was wondering if it was also doable in DarkBASIC.

Thanks for any help.
His Imperial Majesty
18
Years of Service
User Offline
Joined: 19th Sep 2007
Location: Throne World of Korhal
Posted: 10th Jun 2011 06:23
...interpreted as a list.*
Aurum Knight
17
Years of Service
User Offline
Joined: 15th Jul 2008
Location: the suburbs of nowhere
Posted: 10th Jun 2011 07:18
Nope, not in dbpro. For that example there are two basic ways you could go about getting around it. One would be to do basically what you just did, but make the array outside the function and set the values before you call the function. (arrays are automatically global)

Another way, assuming you have a set number of variables you want to pass into the function, would be to make a UDT, set the values, and pass it into the function.

eg
His Imperial Majesty
18
Years of Service
User Offline
Joined: 19th Sep 2007
Location: Throne World of Korhal
Posted: 10th Jun 2011 07:26
Darn, that's too bad. I was hoping to avoid doing it out of the fuction but oh well.

Thanks for your reply.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 12th Jun 2011 12:48
Actually, it's possible when using my plug-ins, but it will be slower and more error prone.



There's also another example written by Diggsey that emulates the C printf function.

Neuro Fuzzy
19
Years of Service
User Offline
Joined: 11th Jun 2007
Location:
Posted: 12th Jun 2011 13:12 Edited at: 12th Jun 2011 13:14
whenever I have a need for an array being passed to a function, I either use strings or pointers. (memory allocation/deallocation/pointers aren't great if you're not familiar with it)

so, those are two other routes.

[edit]
For memory, you either use
make memory/delete memory
or
ianm's alloc/free

basically, the rule of memory management is that every "alloc" must be paired with a "free" - but that's easier said than done!


Why does blue text appear every time you are near?

Login to post a reply

Server time is: 2026-07-10 17:38:27
Your offset time is: 2026-07-10 17:38:27