Type Field to a pointer.type?

Blitz3D Forums/Blitz3D Beginners Area/Type Field to a pointer.type?

Gauge(Posted 2003) [#1]
How can i do this?

p\name$.player=new player

or

p\x#.player=new player

or

p\a.player=new player

Any suggestions?


Miracle(Posted 2003) [#2]
Type player
Field x#, y#, etc#
Field a.player
End Type

p.player = New player
p\a = New player

You now have two players, one referenced by the variable name "p" and the other referenced by player p's "a" field.

I have no idea what you're trying to do in your first two snippets, but whatever it is, it won't work.


Gauge(Posted 2003) [#3]
I'd just like to know how i can use a string, or number for a pointer to a type?
ie:

a$.player=new player

or
a=1
a.player=new player

or
a#=1
a#.player=new player


MSW(Posted 2003) [#4]
when you code something.blah = new blah...blitz assigns a integer number to it...in essence the new command is sorta like a function call in that it returns the handle value for the created type instance...

you can convert this returned integer value into a string and such, but you need to convert it back before doing something with that particular type instance...read up on string conversion functions in the docs...

But, more importantly...why would you want to store such type instance handles as strings/floats?


Floyd(Posted 2003) [#5]
Integers, floats and strings are simply inappropriate for type pointers.

Here is an example of using a type pointer to refer to a particular object.
Type example
	Field n
End Type

Local e.example, middle.example

For k = 1 To 5
	e = New example
	e\n = k
	If k = 3 Then middle = e
Next

For e = Each example 
	Print e\n
Next

Print  :  Print middle\n

middle\n = 999

Print

For e = Each example 
	Print e\n
Next

WaitKey : End



Curtastic(Posted 2003) [#6]
when you need to store a pointer in another variable type you use
p\a%=handle(new player)
p2.player=object.player(p\a%)



Floyd(Posted 2003) [#7]
That certainly lets you use an integer variable a% to store a reference to a type object.
You could even use a$, a string variable.

But what sense does any of this make? We have a new data type called player.
The natural way to refer to this is with a.player, a variable of this new type.

Here is an example.
Type player
	Field n
	Field a.player
End Type

For k = 1 To 4
	t.player = New player
	t\n = k
Next

t = First player
t\a = Last player

Print t\a\n  ; t is the first player, t\a points to the last player
             ; and t\a\n is the n value of t\a, which is 4.

WaitKey : End



Curtastic(Posted 2003) [#8]
maybe he wants to store the pointer in a bank, or have one function parameter that you could pass a string or a pointer with it.


Gauge(Posted 2003) [#9]
Coorae? Could you elaborate on the % thing, I don't really understand it?

Perhaps some code on how i could do this?