Jump to content

Is there an if statement that detects if an entity exists in the world or not?


Recommended Posts

I want to accomplish something to the effect of:

if TheWorld.entityexists("toadstool") then

       stuff

else

        stuff

end

 

Is there any line that would detect this both above and underground?

Edited by Ogrecakes
Link to comment
Share on other sites

18 hours ago, Ultroman said:

I think this'll work.


if c_countprefabs("prefab") > 0 then

I think it MOSTLY works, but it needs to constantly be updating the number.

Currently, if the world is loaded and that prefab does NOT exist, the prefab count will be 0, regardless of if it spawns in later.

If the world is loaded WITH that prefab, the prefab counter will be > 0, regardless of if the prefab ceases to exist.

I probably have to create some timed task to keep on checking the prefab count... I vaguely have an idea of how that would be done, but not exactly.

Edited by Ogrecakes
Link to comment
Share on other sites

You need some instance to start a task on. If it's a world-thing, you can just do:

GLOBAL.TheWorld:DoPeriodicTask(5.0, function(inst)
	if c_countprefabs("prefab") > 0 then
		-- react to there being one
	end
end)

If it's something specific to a character, you should start the task on the character instance instead.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
  • Create New...