. . . Posted August 29, 2016 Share Posted August 29, 2016 (edited) Hello, I need help ... So, my character has some command that makes birds spawn faster for a while which's this if inst.whistle_cooldown == nil then inst.whistle_cooldown = true local birdspawner = TheWorld.components.birdspawner birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX_FEATHERHAT) birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY_FEATHERHAT) inst:DoTaskInTime(90, function() inst.whistle_cooldown = nil end) inst:DoTaskInTime(30, function(inst) local birdspawner = TheWorld.components.birdspawner birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY) birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX) end) end end now the problem is that if you do this command inside caves obviously birds can't spawn in caves so it crashes the game ... So, is there a way I can say like for example if inst.iscave then return end is there some code like "inst.iscave" or something because I don't know what to do, please help me because i'm so dumb ...... I appreciate help so much, thank you so, so much for reading my dumb problem & have a gorgeous day/night !!!!!!!!!!! Edited August 29, 2016 by SuperDavid Link to comment Share on other sites More sharing options...
Lumina Posted August 29, 2016 Share Posted August 29, 2016 there is a tag "cave" if i'm not wrong. Link to comment Share on other sites More sharing options...
. . . Posted August 29, 2016 Author Share Posted August 29, 2016 8 minutes ago, Lumina said: there is a tag "cave" if i'm not wrong. I think you mean "cavedweller" & that's only for entities that live in cave I think. Link to comment Share on other sites More sharing options...
Lumina Posted August 29, 2016 Share Posted August 29, 2016 No, i mean a tag "cave" Here is an example of code i found : local _iscave = inst:HasTag("cave") (in component/ambientlighting.lua) So i guess you could use it to check if cave or not. Link to comment Share on other sites More sharing options...
. . . Posted August 29, 2016 Author Share Posted August 29, 2016 (edited) I just used if inst.whistle_cooldown == nil and not inst.iscave then and got this crash [00:02:48]: [string "../mods/Adam DST Mod/scripts/stategraphs/SG..."]:3348: attempt to index local 'birdspawner' (a nil value) dangit ... welp PS. I tried this to & still same crash if TheWorld.state.iscave then return end *cries* Edited August 29, 2016 by SuperDavid Link to comment Share on other sites More sharing options...
Serpens Posted August 29, 2016 Share Posted August 29, 2016 (edited) the "world" has the tag "cave". But you can also check GLOBAL.GetWorld():IsCave() edit: I'm not 100% sure, if this also works for client, so you should check if this works with caves enabled. I'm not sure, because for items there is a Tag "INLIMBO" and a function IsInLimbo(). The function can only be called from the host, not from clients. The Tag can be checked from both. Edited August 29, 2016 by Serpens Link to comment Share on other sites More sharing options...
. . . Posted August 29, 2016 Author Share Posted August 29, 2016 (edited) @Serpens I did this if inst.whistle_cooldown == nil then if GLOBAL.GetWorld():IsCave() then return end inst.whistle_cooldown = true local birdspawner = TheWorld.components.birdspawner birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX_FEATHERHAT) birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY_FEATHERHAT) inst:DoTaskInTime(90, function() inst.whistle_cooldown = nil end) -- Cooldown = 1.30.0. inst:DoTaskInTime(30, function(inst) local birdspawner = TheWorld.components.birdspawner birdspawner:SetSpawnTimes(TUNING.BIRD_SPAWN_DELAY) birdspawner:SetMaxBirds(TUNING.BIRD_SPAWN_MAX) end) end end, and got crash " [00:00:26]: [string "../mods/Adam DST Mod/scripts/stategraphs/SG..."]:3346: variable 'GLOBAL' is not declared " What did I do wrong ? Edited August 29, 2016 by SuperDavid Link to comment Share on other sites More sharing options...
Serpens Posted August 29, 2016 Share Posted August 29, 2016 (edited) I assumed that your code is in modmain If in modmain, you need to add GLOBAL to most commands. But if your are not, just delete the "GLOBAL." I'm sure you can also make TheWorld:IsCave() --(-> probably only for host) TheWorld:HasTag("cave") --(should always work) Edited August 29, 2016 by Serpens Link to comment Share on other sites More sharing options...
. . . Posted August 29, 2016 Author Share Posted August 29, 2016 (edited) My code's in SGwilson so I just change it to? Thank you @Serpens TheWorld:HasTag("cave") worked perfectly for me she odn't crash the game anymore, thank you so much man !!!!!!! GetWorld():IsCave() Edited August 29, 2016 by SuperDavid Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now