Game Development Community

Storing object in tile position

by Backman · in Torque Game Builder · 06/04/2007 (3:24 pm) · 4 replies

I'm trying to store an object into tiles, the objects themselves aren't actually inside the tiles but on top. I'm doing this so I can get smooth object movement between tiles but still want to be able to easily find out what object is on top of what tile.

I'm storing the object into the tile like $tile[x,y] = %this; but when I delete this object the number still remains inside the tile position? The tile position returns a number like 3422 or similar, I'm guessing this number is the object id?

Basicly I'm wondering what exactly am I storing when doing that above command? If my object has a variable such as health it is possible to do $tile[x,y].tile and it returns it fine. Am I storing a pointer to the object inside this tile position? I just like to figure out how TGB thinks here.

Also, how should I clear this tile position best? I've tried $tile[x,y].safedelete() which probably is silly, storing 0 into it doesn't work either.

Just a bit confused to what I'm actually doing.. it works everywhere apart from the fact it doesn't clear the tileposition holding the object's.. pointer?

Many questions, I hope someone gets what I'm trying to explain here.

#1
06/05/2007 (8:44 am)
Yep, that number is the object's ID number, a reference to the object and not the object itself.

Are you trying to delete the ID from the array? If you're trying to clear the ID from the array, storing 0 or "" should work. Is it still returning the object's ID after you've stored 0?

If you're trying to delete the actual object from the scene, $tile[x,y].safedelete().
#2
06/05/2007 (2:24 pm)
Thanks Melissa, I'm trying to delete the actual object as well as the ref number (thanks for that info as well) to that same object from the tile position. It seems I should use both methods then, only tried one at a time.

Sitting at a different machine just now but will try to store 0 or "" again.. I've just started using Torsion and that showed no change in tile pos when looking in the 'watch' window. Will double check.

Just out of curiosity, is this ref the same thing as a pointer in some programming languages such as C++?

Thanks again!
#3
06/06/2007 (1:25 pm)
Similar to a pointer in use, but it's literally a number - if you have an object with the number "3477", you can even do something like:
(3400 + ("7" @ "7")).getPosition();

Note that if the object has a name, that can be used in the same way, for instance:
("score" @ "Counter").text = "$350";
#4
06/07/2007 (12:44 pm)
Thanks a lot both - feel ever so slightly more enlightened now. :)