MidrealmDM Posted June 20, 2019 Share Posted June 20, 2019 (edited) I am trying to make a 'moooncake' item that glows with brighter and has a bigger light radius as the moon phase changes. I am doing something wrong, because it doesn't work... but I am at a loss on what I need to change The item does not light up at all as is. If I change the default light settings, it lights up, but does not change with the moon phases. So I'm fairly sure the problem is in either overriding the defaults or in recognizing the moon phases. Any advice is welcome. Thank you Spoiler local lightstates = { new = {brightness=0.00, enabled=false, radius=0.00}, quarter = {brightness=0.00, enabled=false, radius=0.00}, half = {brightness=0.25, enabled=true, radius=0.20}, threequarter = {brightness=0.50, enabled=true, radius=0.50}, full = {brightness=0.75, enabled=true, radius=0.70}, } local function onmoonphasechagned(inst) -- function to change light settings, should override default settings. local lightstate = lightstates[TheWorld.state.moonphase] inst.Light:SetIntensity(lightstate.brightness) inst.Light:Enable(lightstate.enabled) inst.Light:SetRadius(lightstate.radius) end local function fn(Sim) local inst = CreateEntity() <snip> -- removed code not relative to this problem inst.entity:AddLight() -- default light settings inst.Light:SetFalloff(.7) inst.Light:SetColour(180 / 255, 160 / 255, 240 / 255) inst.Light:SetIntensity(0.0) inst.Light:Enable(false) inst.Light:SetDisableOnSceneRemoval(true) inst:WatchWorldState("moonphase", onmoonphasechagned) -- should run on moonphasechanged function and update light, but its not working. if not TheWorld.ismastersim then return inst end inst.entity:SetPristine() <snip> -- removed code not relative to this problem return inst end return Prefab( "common/inventory/mooncake_simple", fn, assets, prefabs ) Edited June 20, 2019 by MidrealmDM Link to comment Share on other sites More sharing options...
MidrealmDM Posted June 22, 2019 Author Share Posted June 22, 2019 After some more testing, im pretty sure it is detecting the phase of the moor correctly, its just not overriding the default lighting. Any ideas? Link to comment Share on other sites More sharing options...
Ultroman Posted June 25, 2019 Share Posted June 25, 2019 This line should always be above the ismastersim check IIRC inst.entity:SetPristine() Not that that should fix your problem. I think this might be another one of those problems caused by timing. Perhaps you're setting the moon lighting instantly, whereas the moonlight is actually being lerped to its new values, so it sets its lerp's starting values, you set your values, and the next frame it updates to use the next lerping value. It's just a guess, but see if it works if you delay your changing of the lighting by 5 seconds or at least above how long it takes for the moonlight to lerp in. At least then you'll know if this is the problem. 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