Jump to content

Recommended Posts

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



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]


local function fn(Sim)
  local inst = CreateEntity()

    <snip> -- removed code not relative to this problem

    inst.entity:AddLight() -- default light settings
    inst.Light:SetColour(180 / 255, 160 / 255, 240 / 255)

    inst:WatchWorldState("moonphase", onmoonphasechagned) -- should run on moonphasechanged function and update light, but its not working.
        if not TheWorld.ismastersim then
            return inst
    <snip> -- removed code not relative to this problem

  return inst


return Prefab( "common/inventory/mooncake_simple", fn, assets, prefabs )


Edited by MidrealmDM
Link to comment
Share on other sites

This line should always be above the ismastersim check IIRC


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

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

  • Create New...