Type Field to a pointer.type?
Blitz3D Forums/Blitz3D Beginners Area/Type Field to a pointer.type?
| ||
How can i do this? p\name$.player=new player or p\x#.player=new player or p\a.player=new player Any suggestions? |
| ||
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. |
| ||
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 |
| ||
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? |
| ||
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 |
| ||
when you need to store a pointer in another variable type you usep\a%=handle(new player) p2.player=object.player(p\a%) |
| ||
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 |
| ||
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. |
| ||
Coorae? Could you elaborate on the % thing, I don't really understand it? Perhaps some code on how i could do this? |