better way to do this ?
Monkey Forums/Monkey Programming/better way to do this ?
| ||
Hay all..Local TempPoint:cPoint = new cPoint(100,100) 'add a triangle TempList.AddLast(TempPoint) TempPoint.SetPoint(150,200) TempList.AddLast(TempPoint) TempPoint.SetPoint(200,200) TempList.AddLast(TempPoint) Problem with the above code is that each time I uptdate temppoint and add it to the list, I guess its only adding a pointer, as the values in the list ends up as 3 sets of 200,200. Whats the better way of doing what I'm trying, will I need to create a new local point for each point I add to a shape ? # |
| ||
I could just change the list to an int list instead of a cPoint list , and then just add the values 1 at a time, x then y, etc. but lol I thought I was being clever with the above code.. hope one of you smarty pants can sort me out .. :) |
| ||
For that, you can bypass variable creation altogether, if it suits you, like so:TempList.AddLast(new cPoint(100,100)) TempList.AddLast(new cPoint(150,200)) TempList.AddLast(new cPoint(200,200)) |
| ||
If you want to use objects then you will have to create one for each value you wish to store, yep. Whether that's the best thing to do is another matter. You have to weigh the convenience against the potential GC overhead if you're creating and throwing these values away a lot. |
| ||
Assuming the New() function produces the same results as the SetPoint() function, just do...TempList.AddLast( New cPoint(100,100) ) TempList.AddLast( New cPoint(150,200) ) TempList.AddLast( New cPoint(200,200) ) |
| ||
never mind I was being blond!.. |
| ||
Ah yeah raz thanks m8.. I actually went like this. Local TempPoint:cPoint TempPoint = new cPoint(100,100) TempList.AddLast(TempPoint) TempPoint = new cPoint(150,200) TempList.AddLast(TempPoint) TempPoint = new cPoint(50,200) TempList.AddLast(TempPoint) |
| ||
actually your's looks cleaner im gona use that instead.. lol thanks. see thats what I love about code, always a millions ways to do something. |
| ||
@Taiphoz: see thats what I love about code, always a millions ways to do something. That's not always a good thing. :) |