42 lines
1.2 KiB
Lua
42 lines
1.2 KiB
Lua
-- ============================================================================
|
|
-- 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
|