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.

Newcomers DBPro Corner / returning user defined datatypes in a function

Author
Message
pollywog
17
Years of Service
User Offline
Joined: 18th Jan 2007
Location:
Posted: 26th Jun 2007 02:36
Is it possible to return a user defined type in a function?

alien = UpdateCharacter(alien)



function UpdateCharacter(pCharacter as CHARACTER)
pcharacter.blah = x
pcharacter.location = x
pcharacter.activity = getActivity(aCharacter)
end function pCharacter
indi
22
Years of Service
User Offline
Joined: 26th Aug 2002
Location: Earth, Brisbane, Australia
Posted: 26th Jun 2007 07:03
This example demonstrates that you can use a type or type with array as the actual parameter in a function, however you can hand back to it inside the function.



it also demonstrates that array based types and types are global into the function without a parameter call.

Bishop
21
Years of Service
User Offline
Joined: 18th Dec 2002
Location: In my favorite chair...
Posted: 29th Jun 2007 10:06 Edited at: 29th Jun 2007 11:30
Not sure if you could do that using local variables, but using Arrays and Types, you could do it. Kind of a pain in the ass to have to have a bunch of Global variables running around, but oh well ^^

Use the Type/ Endtype to define your data:



Then define an array and use your Character type to define it:



Now you can call and define these data types in any part of your code:



In this fashion, you won't have to worry about returning a value with the function as you can call the array anywhere in the code. More memory usage =P

Cheers,
Bishop

*EDIT*

Don't forget, you can use user defined types to define other custom types =P for example:



...is quite cool for keeping track of positions. It can be used for game data like this:


This way, you can call the players stuff like this;




Tux is my guildmaster.

Login to post a reply

Server time is: 2024-09-27 01:21:33
Your offset time is: 2024-09-27 01:21:33