Jump to content

World:Reset()


Rick
 Share

Recommended Posts

Might be nice to have a Reset() function on the world which would cycle through each entity and call a Reset() script function in the case where it would take longer to reload a map than to just reset some information. The details of resetting would be up to the user.

 

I guess if you took this to a more generic approach it might be handy to be able to call any function ALL scripts might have defined from the world. Something like:

 

World:CallEvent("Reset", extra)

 

There might be other uses to do something with this. Like "Save" to let entities save their information when we need to save the game.

Link to comment
Share on other sites

Did some searching, use tolua++ to expose these functions and they'll do exactly what you want.

 

 //Script

virtual bool CallFunction(const std::string& name, Object* extra=NULL);

virtual bool CallFunction(const std::string& name, Entity* entity, const Vec3& position, const Vec3& normal, const float speed);

 

Then in Lua:

-- One entity
self.entity:CallFunction("Reset",extra)
-- Do All Entites!
for i=0,world:CountEntities()-1 do
world:GetEntity(i):CallFunction("Reset",extra)
end

  • Upvote 2

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

I know I could do this. The request was mainly asking for it to be built into the engine as a useful feature for users without requiring them to do anything extra. This request wasn't for me but just a general request that would help people of the engine.

Link to comment
Share on other sites

Ahh, but in this case, it's already built in. More commands just need to be exposed to lua, that's all. In the meantime, how bout this?

 

for i=0, world:CountEntities()-1 do
local entity = world:GetEntity(i)
if entity.script then
if type(entity.script.Reset)=="function" then
entity.script:Reset()
end
end
end

 

Stick that in your changelevel loop after Map::Load()

  • Upvote 1

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

Ahh, but in this case, it's already built in. More commands just need to be exposed to lua, that's all.

 

Yep, that's why I'm asking Josh to do this since in this feature request (I take this forum for official requests to make it into the engine and supported) it shouldn't take much for him to officially support it. The thing with "work arounds" (if you can call it that) is that if it's not officially supported it rarely gets used. Also, I know I use world:CountEntities() and world:GetEntity() but I believe Josh has stated those aren't officially supported so they could change. I wish they would be official though honestly.Believe me, I do tons of "work arounds" for things but I always want things to be official so they are part of the engine and documented/supported for newer users to use as well.

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...