Jump to content

Instance Already Exist?


Recommended Posts

I've found two unique methods... unique as in complicating

 


 

for GUID, instance in pairs(Ents) do

    if instance.prefab == "wolfgang" then

         print("the power comes from the moustache!")

    end

end

in modmain, you need to use Ents global, ofc.

 


 

TheSim:FindFirstEntityWithTag("wall")

Link to comment
Share on other sites

Thanks for the reply.

 

I tried both methods but they doesn't seem to work. I don't know if I'm using them correctly...

 

local exist = falsefor GUID, instance in pairs(Ents) do    if instance.prefab == "myprefab" then         exist = true    endendif not exist then    AddSimPostInit(SpawnItem)end

or

if not TheSim:FindFirstEntityWithTag("mytag")         AddSimPostInit(SpawnItem)end

Another thing is all my print aren't showed in the console. Maybe I'm not using the right console...?

 

Thanks in advance for the future reply

 

 

Link to comment
Share on other sites

Thanks for the reply.

I tried both methods but they doesn't seem to work. I don't know if I'm using them correctly...

local exist = falsefor GUID, instance in pairs(Ents) do    if instance.prefab == "myprefab" then         exist = true    endendif not exist then    AddSimPostInit(SpawnItem)end

or

if not TheSim:FindFirstEntityWithTag("mytag")         AddSimPostInit(SpawnItem)end

Another thing is all my print aren't showed in the console. Maybe I'm not using the right console...?

 

Thanks in advance for the future reply

 

Try looking up your log.txt in documents/Klei/DoNotStarve and going to the error shown in the error screen (it should be followed by an indent stack traceback). That usually tells you a hint.

 

The latter lacks an "then" at the end of the first line.

Furthermore, have you defined "SpawnItem" anywhere? maybe you meant to do SpawnPrefab("myitem").Transform:SetPosition(GetPlayer():GetPosition) to spawn it at the players position.

 

Also, if SimPostInit doesn't work, try GamePostInit. Not sure what the difference is tbh.

Link to comment
Share on other sites

Thanks for the reply.

 

SpawnItem is defined and it work perfectly it's just that I want it to only spawn once after the world generation.

 

In fact it isn't giving me an error, it just keeps spawning the item everytime I enter the game which mean it keeps calling AddSimPostInit(SpawnItem).

 

That's why I needed a condition so it won't call it every time I enter the game. I needed to find the number of instance of the object to whether call it or not.

 

For the missing "then" I had it placed it's just I forgot it on the post ^^'

 

so in overall it keeps thinking that the object doesn't exist and spawn it...

 

Thanks for the future reply!

Link to comment
Share on other sites

Well I fixed my problem, I got a function that verify if the item already exist then I don't know why but I had to put the condition into a function that I called MyPostInit() for it to take effect then call it into the AddSimPostInit(MyPostInit)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...