This commit is contained in:
Jan Racek
2026-03-29 09:34:46 +02:00
commit 1fdb223f5d
113 changed files with 17499 additions and 0 deletions

41
Assets/lua/switch.lua Normal file
View File

@@ -0,0 +1,41 @@
-- ============================================================================
-- switch.lua - Toggle switch that activates/deactivates a target object
-- ============================================================================
-- Tests: onInteract, Entity.Find, Entity.IsActive, Entity.SetActive,
-- Audio, self properties
local target = nil
local switchOn = false
function onCreate(self)
switchOn = false
-- Find the object this switch controls (named "SwitchTarget")
target = Entity.Find("SwitchTarget")
if target then
Entity.SetActive(target, false)
Debug.Log("Switch: found target, initially off")
else
Debug.Log("Switch: WARNING - SwitchTarget not found!")
end
end
function onInteract(self)
switchOn = not switchOn
if target then
Entity.SetActive(target, switchOn)
end
if switchOn then
Audio.Play("switch_on", 100, 64)
setStatus("Switch ON")
else
Audio.Play("switch_off", 100, 64)
setStatus("Switch OFF")
end
-- Test Entity queries
local count = Entity.GetCount()
Debug.Log("Switch toggled. Total entities: " .. count)
Debug.Log("Target active: " .. tostring(Entity.IsActive(target)))
end