doubt with types

Blitz3D Forums/Blitz3D Beginners Area/doubt with types

David(Posted 2004) [#1]
i have a doubt.

--------------------------
Type OrionSound
Field agua.dibSound
...
End Type
g_OrionSound.OrionSound = New OrionSound

; In this function modify "dibSoundUse"
dibSoundLoad( "motor\sounds\agua.wav", False, True )

; is my doubt
g_OrionSound\agua = dibSoundUse
-------------------------------

copy type or copy handle?

and other:
- cant return a type from function
- cant insert a dim in a type

thanks


soja(Posted 2004) [#2]
1) It copies the handle. You must implement your own copy methods if you wish the object to be copied.

2) Yes you can:
Function MyFunction.CustomType()
    ...
    Return c.CustomType
End Function

3) You must use a "BlitzArray" -- an array with [] instead of (), like this:
Field ArrayName%[5]
.

Search for "BlitzArray" in the forums to see advantages/disadvantages and caveats.


Zethrax(Posted 2004) [#3]
"g_OrionSound\agua = dibSoundUse copy type or copy handle?"

Since the 'agua.dibSound' field is a type pointer, you can only copy another pointer value of the 'dibSound' type into it, so 'dibSoundUse' would need to have been declared as 'dibSoundUse.dibSound' or you will get an error.

---

"cant return a type from function"

Yes, you can return a type pointer value from a function, but the function needs to be setup to return the correct data type by specifying the data type after the function name when you declare the function (the same as with the standard data types, except integers which are the default data type returned). Also, you can only transfer pointer values between type pointer variables of the same type.

eg.
Function my_function.my_type()
Return my_type_pointer.my_type
End Function

my_other_type_pointer.my_type = my_function()

---

"cant insert a dim in a type"

No, you can't do that, but there is an unofficial, undocumented sort of array you can use, called a Blitz array. These use square brackets instead of parenthesis, can't be redimensioned, can be local within functions, can be of any standard or custom data type like normal arrays (as far as I'm aware anyway), and can be used in types.

Like I said, they are unofficial, so they could be altered or removed from Blitz in a future update. I don't think this is very likely, though. They're too useful. You can find out more about them over at www.Blitzcoder.com , in the 'Undocumented' section.

eg.
Type mytype
Field a_blitz_array$[ 10 ]
End Type

my_pointer.mytype = New mytype

my_pointer\a_blitz_array$[ 1 ] = "abcd"

Print my_pointer\a_blitz_array$[ 1 ]


David(Posted 2004) [#4]
very thanks :)