Jump to content

[ Solved ]Get Sun World Settings?


Go to solution Solved by Josh,

Recommended Posts

Posted

The sun will be stored as a directional light in the scene.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted
15 minutes ago, Josh said:

The sun will be stored as a directional light in the scene.

Do you have a tag or something similar to get it back?

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Posted

Just cast each entity in scene->entities to a DirectionalLight. The only one that isn't NULL is the sun.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted
2 hours ago, Josh said:

Just cast each entity in scene->entities to a DirectionalLight. The only one that isn't NULL is the sun.

I'm stuck here. :(

 

function this:LoadScene(mapName)
        scene = LoadScene(world, mapName)
        mapName = mapName
        Print("[World] Mapa cargado: " .. mapName)
 
        local sun = nil
 
        for i = 0, #scene.entities   do
            local entity = scene.entities[i]
            Print("XXXX"..tostring( entity))
           
            --local light = entity:CastToDirectionalLight()
           -- if light ~= nil then
                --sun = light
               -- break
            --end
        end
       
       
    end

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Posted
15 minutes ago, Dreikblack said:

Casting in lua looks like this:

sun = DirectionalLight(entity)

function this:LoadScene(mapName)
        scene = LoadScene(world, mapName)
        mapName = mapName
        Print("[World] Mapa cargado: " .. mapName)
 
        local sun = nil
 
        for i = 0, #scene.entities   do
            local entity = scene.entities[i]
            local light = DirectionalLight(entity) --Not Work.
           
           
           
 
           
        end
       
       
    end

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

Posted

There is always an easy way to find out what is in the API. Just type the function name into the editor console and press return, and it will tell you the value or type of the variable. When I do this, I can see that DirectionalLight is a function.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

  • Solution
Posted
if sun ~= nil then break end

Put that inside the loop after getting sun.

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Posted

I'll go to sleep in peace. Today I learned something by brute force, the sun is off in the editor, so that's why nil returned. Thank you all for the patience.

image.thumb.png.c5d901362bfe13f68f08d84db27e9783.png

 

function this:LoadScene(mapName)
        scene = LoadScene(world, mapName)
        mapName = mapName
        Print("[World] Mapa cargado: " .. mapName)
 
        local sun = nil
 
        for i = 1, #scene.entities    do
            local entity = scene.entities[i]
         
             sun = DirectionalLight( entity)
 
             if sun ~= nil then break end
         
         
           
        end
 
       sun:SetHidden(true)
       
    end

 

 

Astrocuco.thumb.png.c76e0fb3de2d6e437e7dca099625e11e.png

  • Yue changed the title to [ Solved ]Get Sun World Settings?
Posted

AI integration could have saved a lot of time here:

Quote

 

fix any errors in this Lua code. Your response should consist only of Lua code. Clearly mark the sections of the code you are changing, and add explanations of your changes in code comments. Do not add any additional information other than pure Lua code.

It makes some comments that make no sense, but it did catch two errors.

function this:LoadScene(mapName)
    scene = LoadScene(world, mapName) -- Changed: Ensure 'scene' is properly defined
    -- mapName = mapName -- Removed: This line is redundant and does nothing
    Print("[World] Mapa cargado: " .. mapName)

    local sun = nil

    for i = 1, #scene.entities do -- Changed: Start loop from 1 instead of 0, as Lua arrays are 1-indexed
        local entity = scene.entities[i]
        local light = DirectionalLight(entity) -- Ensure 'DirectionalLight' is a valid function
    end
end

What if the IDE could send the printed error messages, the stack trace, and the lua code file to Deep Seek for analysis every time a syntax or runtime error occured, and it just automatically corrected the code?

  • Like 1

My job is to make tools you love, with the features you want, and performance you can't live without.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...