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 / Editing a type from an array from a function

Author
Message
Tsproggy
14
Years of Service
User Offline
Joined: 2nd Jan 2012
Location: Reno, Nevada
Posted: 28th Jan 2012 03:32
Hello,

I have a type I made to oragnize my npcs such as



I have an array which uses my custom type:


But my problem is unless I call the specific NPC by name (directly) I can't seem to edit any of it's properties.

Example of what I can do:
Tsproggy
14
Years of Service
User Offline
Joined: 2nd Jan 2012
Location: Reno, Nevada
Posted: 28th Jan 2012 04:38
Woa.. it only posted half of it.. Basically it can read from my types but if I try to edit it's values from a function it doesn't work. I've ran into this problem in C# before and I had to change my function's accepted arguments like:

"Private Void MyFunc(ByVal MyArg1, ByVal MyArg2)"

I don't know if there are the same keywords (ByVal, ByRef) in DarkBASIC so I was hoping someone could tell me if it's possible or what methods to use.

I haven't failed 1,000 times! I've just found 1,000 ways something won't work.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th Jan 2012 14:25
Hi

DBPRO cannot return user defined types from functions. You won't be able to pass in a UDT array as a parameter either.

What you can do is pass in an index for the array element, and change its values globally



You don't have all the freedom in the world, but at least this allows you to edit UDT arrays within a function.

There is also a library made by Diggsey which allows you to work with references to UDT variable elements from functions, but this is more advanced.

Note that you can pass in a UDT variable into a function, but not an array variable; something like this would be necessary:



Tsproggy
14
Years of Service
User Offline
Joined: 2nd Jan 2012
Location: Reno, Nevada
Posted: 28th Jan 2012 18:53
Thank you sir,

You are a gentleman and a scholar! I hadn't thought of accepting the UDT Array's index as a function argument. I also thank you for the explanation. It's useful knowing limitations so I can attempt ways around them hehe.

I haven't failed 1,000 times! I've just found 1,000 ways something won't work.
Chris Tate
DBPro Master
17
Years of Service
User Offline
Joined: 29th Aug 2008
Location: London, England
Posted: 28th Jan 2012 19:27
No problem bud!

Dar13
18
Years of Service
User Offline
Joined: 12th May 2008
Location: Microsoft VisualStudio 2010 Professional
Posted: 29th Jan 2012 00:08
Quote: "You won't be able to pass in a UDT array as a parameter either. "

Well, not technically, but you can if you're willing to go fiddle around with array pointers.

Something like this should work(haven't tested, might not even use correct keywords):

Unless I'm mistaken, which is most likely the case.

Login to post a reply

Server time is: 2026-07-09 20:54:58
Your offset time is: 2026-07-09 20:54:58