Passing strings to a type

BlitzMax Forums/BlitzMax Beginners Area/Passing strings to a type

Takis76(Posted 2013) [#1]
I have and another one newbie question.
How to pass a string in a type.

For example

Type My_Type 

   field the_string:string

Endtype
The_type:My_Type


If I will try to use

The_type.the_string="Blah"

The program crashes.

Any idea? :o)


TomToad(Posted 2013) [#2]
You need to use new before using the type
The_type:My_Type = new My_Type


Derron(Posted 2013) [#3]
Another common approach is using:

Type XY
Function Create:XY(params)
local obj:XY = new obj
obj.param1 = param1
return obj
End Function
End Type


Global The_Type:XY = XY.Create(params)



bye
Ron


Takis76(Posted 2013) [#4]
And if my type is an array?

Type My_Type 

   field the_string:string

Endtype
The_type:My_Type[100]



The_type:My_Type= new My_Type[100] drops error

I tried all kinds of

The_type:My_Type[100] = new My_Type
The_type:My_Type[100] = new My_Type[100]

Or

The_type[100]:My_Type = new My_Type
????


col(Posted 2013) [#5]

And if my type is an array?



Each element in the array needs to 'New'd indiviually.

Global Array:My_Type[100]

For Local i = 0 until 100
Array[i] = New My_Type
Next



Takis76(Posted 2013) [#6]


Each element in the array needs to 'New'd indiviually.

Global Array:My_Type[100]

For Local i = 0 until 100
Array[i] = New My_Type
Next




At last it worked. THANK YOU VERY VERY MUCH.
My game now went one step farther.

There is not any in depth manual to explain these.