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 / User Defined Types

Author
Message
heyworth83
21
Years of Service
User Offline
Joined: 26th Nov 2002
Location: United Kingdom
Posted: 18th Aug 2003 23:42
Can someone please let me know (if it can be done) how to send and object (or should I say a variable created from a user defined data type) as a parameter to a function? I just get the error "Unknown Parameter" when I try to compile. I've provided code. Thanks.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Aug 2003 00:15
The function here is not necessary and the syntax is wrong.

See my post in the General Forum under "CODENATION --> DB TUTORIALS"


hope this helps
RUST

How do ya do there son
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Aug 2003 00:20
And after you read that I would say you need to define the function's args in the function declaration like

FUNCTION MyFunc(MyVar AS Integer)
da codez
EndFunction MyReturnVariable

Also, call the function on the right side of an equation to set a value on the left...

MyNeededValue=MyFunc(intSomeArg)


RUST

How do ya do there son
heyworth83
21
Years of Service
User Offline
Joined: 26th Nov 2002
Location: United Kingdom
Posted: 19th Aug 2003 00:40
thanks - my function was weird because it was just an example. but i'll try that out what you said.
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Aug 2003 00:49
cool - Good Luck
Rust

How do ya do there son
heyworth83
21
Years of Service
User Offline
Joined: 26th Nov 2002
Location: United Kingdom
Posted: 19th Aug 2003 22:30
The function works OK but i still can't send an 'ENEMY' object from the ENEMY class as a parameter in the function. Maybe it's a bug of DBPro? What do you reckon? Or maybe i'm just an idiot and the solution is looking me in the face.
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 19th Aug 2003 23:01
Passing types to functions will be available with Update5, but they will be 'pass by value', ie you pass a copy of the type
CattleRustler
Retired Moderator
21
Years of Service
User Offline
Joined: 8th Aug 2003
Location: case modding at overclock.net
Posted: 19th Aug 2003 23:48
for now, until U5, pass the property ThisEnemy.strength to the function, set it there, and you are done. U5 might have something like

Function LoadEnemyData(typEnemy as Enemy)

With typEnemy
.strength=1
.name=joe
.someproperty=somevalue
.someotherproperty=someothervalue
.someotherproperty=someothervalue
.someotherproperty=someothervalue
.someotherproperty=someothervalue
end With

End Function

but this function is really not necessary as a SUB would do the trick

we'll see

-RUST-
IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Aug 2003 01:09
Nope. Types are passed by value. Changing the value inside the function does not affect the original outside the function.
dark puppus
21
Years of Service
User Offline
Joined: 16th Aug 2003
Location:
Posted: 20th Aug 2003 01:32 Edited at: 20th Aug 2003 01:34
and if i write something like this ? with U5 it does work ???



What i would say is : can i create a function wich accept a user defined type on input and output another (or the same) user defined type ?

IanM
Retired Moderator
22
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 20th Aug 2003 01:37
No, you can't return a type yet ... but hopefully for Update6
MicroMan
21
Years of Service
User Offline
Joined: 19th Aug 2003
Location: Stockholm, Sweden
Posted: 20th Aug 2003 10:10
Couldn't you pass a pointer to the variable instead? That would perhaps be easier than passing along a whole type -- unleass you want to manipulate everything in the type...

You can pass 255 values to the function. Also, by passing pointers you get access to the variables of the main program indirectly through the memory addresses you're passing along.
MicroMan
21
Years of Service
User Offline
Joined: 19th Aug 2003
Location: Stockholm, Sweden
Posted: 20th Aug 2003 10:13
Here's the code which I included in the post above, but I can't see it. Sorry for the repetition if someone CAN see it.

Login to post a reply

Server time is: 2024-11-25 04:45:47
Your offset time is: 2024-11-25 04:45:47