Objects and types

Blitz3D Forums/Blitz3D Beginners Area/Objects and types

Tau_Aquilae(Posted 2011) [#1]
Is it possible to use a command that effects ALL objects connected to a type? I'll put my current issue out to clarify.

Current issue: When I use a collision command, I want the player entity to collide with every object that gets it's data fields from the "Landscape" type (since terrain was apparently taken) whether it be a "ice_land" object or a "metal_land" object or whatever.

Last edited 2011


Yasha(Posted 2011) [#2]
Function CheckAllLandscapes(ent)
    Local l.Landscape, colCount = 0
    For l = Each Landscape
        colCount = colCount + CheckSingleCollision(ent, l)      ;...?
    Next
    Return colCount
End Function


The important part of this is the For/Each loop, which iterates over every existing object of a particular type.


Tau_Aquilae(Posted 2011) [#3]
gotcha, that makes sense thanks! (Sidenote: and I have no idea about how the double post entered existence....)


Yasha(Posted 2011) [#4]
There's one other cool one (forgot yesterday) that's not really important but worth knowing too:

Delete Each Landscape


...will, surprisingly enough, remove every object of type Landscape.

This is obviously only useful if your objects don't include textures or other resources that need to be freed separately - for that, you'll need a proper destructor function, or to put your other deletion code in a full For/Each loop (a For/Each loop will still find the Next object for the Next iteration even if the code in the loop body Deletes the previous object).