Yue Posted April 6 Posted April 6 How can I retrieve the sun from the map to create a night and day effect? Quote
Josh Posted April 6 Posted April 6 The sun will be stored as a directional light in the scene. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Yue Posted April 6 Author Posted April 6 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? Quote
Josh Posted April 6 Posted April 6 Just cast each entity in scene->entities to a DirectionalLight. The only one that isn't NULL is the sun. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Yue Posted April 7 Author Posted April 7 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 Quote
Dreikblack Posted April 7 Posted April 7 Casting in lua looks like this: sun = DirectionalLight(entity) 1 Quote
Yue Posted April 7 Author Posted April 7 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 Quote
Josh Posted April 7 Posted April 7 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. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Josh Posted April 7 Posted April 7 @Yue Arrays in Lua start with 1, not 0. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Solution Josh Posted April 7 Solution Posted April 7 if sun ~= nil then break end Put that inside the loop after getting sun. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Yue Posted April 7 Author Posted April 7 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. 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 Quote
Josh Posted April 7 Posted April 7 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? 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without.
Recommended Posts
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.