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 types back from functions - should this work?

Author
Message
Ratty Rat
23
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 31st Oct 2003 17:19
In the code below I try to get a variable of a type passed back from a function straight into another variable of that type.

When compiling I get the error '#100047: Both user defined values must use the same type at line #'.

Am I doing something wrong or does this simply not work?

"Don`t try to engage my enthusiasm, I don`t have one"
Toothpick
23
Years of Service
User Offline
Joined: 9th Feb 2003
Location:
Posted: 31st Oct 2003 17:37
I cant see your code also cant see the "code" button, but i know
there are problems with types and functions.
Ratty Rat
23
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 31st Oct 2003 17:43
Here is the code (should be on the 'source' button, works for me) :-

TYPE TEST
I AS INTEGER
S AS STRING
ENDTYPE

C AS TEST

C = (MAKEIT(J, "TEST" ))

PRINTIT( C )

SYNC

WAIT KEY

END

FUNCTION PRINTIT( B AS TEST )

PRINT B.S
B.S = ""

ENDFUNCTION

FUNCTION MAKEIT( I AS INTEGER, S AS STRING )
OUT AS TEST

OUT.I = RND(255)
OUT.S = S + "."

ENDFUNCTION OUT

"Don`t try to engage my enthusiasm, I don`t have one"
Shadow Robert
23
Years of Service
User Offline
Joined: 22nd Sep 2002
Location: Hertfordshire, England
Posted: 31st Oct 2003 19:07
you need to declare them as globals within the function, but then you can't use them more than once (catch22)

and you can't actually export them yet either, only import...
when you try to export either they'll crash or simply return the first type variable.


To Survive You Must Evolve... This Time Van Will Not Escape His Fate!
Toothpick
23
Years of Service
User Offline
Joined: 9th Feb 2003
Location:
Posted: 1st Nov 2003 01:07
nope cant see the source button, must be a prob at my end.

a way around it might be to have an array of the type and pass the index number in and out of the function.

Or have one global type and blank the data before using it in a function.
_____________________________________________
TYPE TEST
I AS INTEGER
S AS STRING
ENDTYPE

out as test

C AS TEST




MAKEIT(J, "TEST",out )


C = out

PRINTIT( C )

SYNC

WAIT KEY

END

FUNCTION PRINTIT( B AS TEST )

PRINT B.S
B.S = ""

ENDFUNCTION

FUNCTION MAKEIT( I AS INTEGER, S AS STRING, tp as test )
tp.I=0
tp.S=""
`not really needed here


tp.I = RND(255)
tp.S = S + "."

ENDFUNCTION
___________________________________________________


_____________________________________________
TYPE TEST
I AS INTEGER
S AS STRING
ENDTYPE

global trans as integer


trans=1

C(1) AS TEST
`max value used for data transfer



C(0)= C( MAKEIT(J, "TEST") )




PRINTIT( C )

SYNC

WAIT KEY

END

FUNCTION PRINTIT( B AS TEST )

PRINT B.S
B.S = ""

ENDFUNCTION

FUNCTION MAKEIT( I AS INTEGER, S AS STRING )

C(trans).I = RND(255)
C(trans).S = S + "."

ENDFUNCTION trans
___________________________________________________


and so on.
Ratty Rat
23
Years of Service
User Offline
Joined: 24th Sep 2002
Location:
Posted: 3rd Nov 2003 12:55
Thanks,
I think I`ll keep one global instance of the type for passing out of functions, then copy it into the local instance, as I noticed that doing 'A = B' where they are both of the same type seems to work OK.

"Don`t try to engage my enthusiasm, I don`t have one"

Login to post a reply

Server time is: 2026-07-26 16:04:19
Your offset time is: 2026-07-26 16:04:19