Yue Posted April 6, 2025 Posted April 6, 2025 How can I retrieve the sun from the map to create a night and day effect? Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted April 6, 2025 Posted April 6, 2025 The sun will be stored as a directional light in the scene. 1 Quote Let's build cool stuff and have fun.
Yue Posted April 6, 2025 Author Posted April 6, 2025 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 Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted April 6, 2025 Posted April 6, 2025 Just cast each entity in scene->entities to a DirectionalLight. The only one that isn't NULL is the sun. 1 Quote Let's build cool stuff and have fun.
Yue Posted April 7, 2025 Author Posted April 7, 2025 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 Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Dreikblack Posted April 7, 2025 Posted April 7, 2025 Casting in lua looks like this: sun = DirectionalLight(entity) 1 Quote Check out Slipgate Tactics - turn based tactics Quake fan game, which is made with Ultra Engine/Leadwerks 5: https://www.leadwerks.com/community/topic/61480-slipgate-tactics-demo/
Yue Posted April 7, 2025 Author Posted April 7, 2025 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 Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Dreikblack Posted April 7, 2025 Posted April 7, 2025 Maybe @Joshdid not yet added it 1 Quote Check out Slipgate Tactics - turn based tactics Quake fan game, which is made with Ultra Engine/Leadwerks 5: https://www.leadwerks.com/community/topic/61480-slipgate-tactics-demo/
Josh Posted April 7, 2025 Posted April 7, 2025 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 Let's build cool stuff and have fun.
Josh Posted April 7, 2025 Posted April 7, 2025 @Yue Arrays in Lua start with 1, not 0. 1 Quote Let's build cool stuff and have fun.
Yue Posted April 7, 2025 Author Posted April 7, 2025 Run but don't get anything back. Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Solution Josh Posted April 7, 2025 Solution Posted April 7, 2025 if sun ~= nil then break end Put that inside the loop after getting sun. 1 Quote Let's build cool stuff and have fun.
Yue Posted April 7, 2025 Author Posted April 7, 2025 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 Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Josh Posted April 7, 2025 Posted April 7, 2025 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 Let's build cool stuff and have fun.
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.