pointers?
BlitzMax Forums/BlitzMax Programming/pointers?
| ||
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? |
| ||
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. |
| ||
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. |
| ||
Make your master a proxy object, that contains as a reference the current master object in question. |
| ||
i.etype 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?) |
| ||
(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. |
| ||
hurrah, you got it! :D |