Sign in to follow this  
Ogrecakes

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

Recommended Posts

Ogrecakes    882
Posted (edited)

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

Share this post


Link to post
Share on other sites
Ultroman    450
Posted (edited)

I think this'll work.

if c_countprefabs("prefab") > 0 then
Edited by Ultroman
  • Thanks 1

Share this post


Link to post
Share on other sites
Ogrecakes    882
Posted (edited)
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

Share this post


Link to post
Share on other sites
Ultroman    450

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.

Share this post


Link to post
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

Sign in to follow this