Jump to content

Clearing the world


Alienhead
 Share

Recommended Posts

I'm attempting to clear an active world..  Say the player wishes to restart the map, not a /sav but a complete restart of the map that loaded upon entering the game.

So far I'm attempting to do it this way:

if window:KeyHit(KEY_F2) then 
        scene=nil
        collectgarbage()
        scene = LoadMap(world, mapname)
end

But it leaves stuff behind, decals, and any other entity or game object I have referenced elsewhere in my code.  

Sure could use some advice on this one, I'm stumped.

I know this will be a question asked 100's of time once you get 1.0 released customers in here... Do you think it may be a big enough deal to include a world:Clear() / world:Unload() /  scene:Wipe() / scene:Kill()   or something ?

As it stands Im pretty much guessing and hoping stuff got cleared with nil, its not reassuring. 

If not, then maybe a clear path to as what needs to be done to restart a map without lingering 'things' in the world/scene. 

 

 

 

 

 

Link1 || Alienhead Components and Software || Link2

Link to comment
Share on other sites

Sounds like you have objects/pointers still in use. Ultra Engine uses smart pointers and if something is still pointing to an object or entity, the entity will not be deleted. 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Going to be pretty rough clearing a map/scene all the way out then. :(

Guess I'll just have to go through all my code and grab all the table and variable names pointing to something.

So for example, something like the player component, which opens up a lot of tables and variables on it's own, won't scene = nil kill the player component and thus all it contains ? Or I'm still needing to clear that first before scene = nil?

 

Thanks.

 

 

Link1 || Alienhead Components and Software || Link2

Link to comment
Share on other sites

A scene can be cleared without deleting an entity if the entity is still being referenced by something else. In C++, this would normally mean you're using another shared pointer as a reference when you should be using a weak pointer. No clue about Lua to be honest. 

Cyclone - Ultra Game System - Component PreprocessorTex2TGA - Darkness Awaits Template (Leadwerks)

If you like my work, consider supporting me on Patreon!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...