pointers?

BlitzMax Forums/BlitzMax Programming/pointers?

Robert Cummings(Posted 2005) [#1]
Hiya

I have a linked list in Blitzmax using types etc...

Say five of these items in the list reference a 6th item.

ball.x = ball.master.x

An item holds the 6th item (the master) as .master, and can use it's data.


The problem here is master will at some point be deleted, and the mantle of master will be passed to a different ball.

How do I make all the other balls update their master variable type without going through the entire list and manually setting them? It's not a major problem to do this but I thought it might be quite nice if there's an elegent and fast solution such as pointers or something?


Perturbatio(Posted 2005) [#2]
if master holds pointers to all it's children then you could do it quicker than iterating the list, but you are going to have to loop through them regardless.


ImaginaryHuman(Posted 2005) [#3]
If you store your `master` in an external variable, in an array of them, you can just refernce the index in the array from each item when you create them, then if the master changes you can just update the array.


FlameDuck(Posted 2005) [#4]
Make your master a proxy object, that contains as a reference the current master object in question.


Warpy(Posted 2005) [#5]
i.e
type deathbychocolate
  field bigandshiny:spoon
end type

type spoon
  field x,y
end type

type gorilla
   field x,y
   field taxreturn:deathbychocolate
end type

horationelson:deathbychocolate=new deathbychocolate
beltbuckle:spoon=new spoon
beltbuckle.x=1
horationelson.bigandshiny=beltbuckle
gorillas:gorilla[] = [new gorilla,new gorilla, new gorilla]
for c=0 to 2
   gorillas[c].taxreturn=horationelson
next
print gorillas[1].taxreturn.bigandshiny.x

patiofloor:spoon=new spoon
patiofloor.x=2
horationelson.bigandshiny=patiofloor
print gorillas[2].taxreturn.bigandshiny.x


(I'm trying a new style of obfuscation. You like?)


FlameDuck(Posted 2005) [#6]
(I'm trying a new style of obfuscation. You like?)


Yes I'm a big fan of the "If you can't make your source code understandable, at least make it entertaining" school of thought.


Warpy(Posted 2005) [#7]
hurrah, you got it! :D