Welcome to Smart Home Forum by FIBARO
Dear Guest,
as you can notice parts of Smart Home Forum by FIBARO is not available for you. You have to register in order to view all content and post in our community. Don't worry! Registration is a simple free process that requires minimal information for you to sign up. Become a part of of Smart Home Forum by FIBARO by creating an account.
As a member you can:
- Start new topics and reply to others
- Follow topics and users to get email updates
- Get your own profile page and make new friends
- Send personal messages
- ... and learn a lot about our system!
Regards,
Smart Home Forum by FIBARO Team
Question
xirilius 0
Hello,
Is it posible in HC2 LUA to create global functions?
I use o lot of functions over and over again and have to include them in every scene
Is it possible to create functions in a centralized scene and use them from every other scene?
Example:
------------------------------------------------------------------------------------
GlobalFunctions
------------------------------------------------------------------------------------
global function BeepXseconds(x)
fibaro:call(42, "turnOn")
fibaro:sleep(x * 1000)
fibaro:call(42, "turnOff")
end
global function MyDebug(text, color)
-- read GlobalGlob
if DebugGlob = true then
-- do something with formatting text, add OS.date and add colors
fibaro:debug(text)
end
end
------------------------------------------------------------------------------------
now i can use the global functions in other scenes
------------------------------------------------------------------------------------
scene 161 - TurnAlarmOn
------------------------------------------------------------------------------------
-- do something
MyDebug("Turn Alarm on", "red")
BeepXseconds(5)
-- do something
------------------------------------------------------------------------------------
------------------------------------------------------------------------------------
scene 254 - Doorbell
------------------------------------------------------------------------------------
-- do something
MyDebug("Someone is ringing", "BLUE")
BeepXseconds(2)
-- do something
------------------------------------------------------------------------------------
AND OFCOURSE I CAN CREATE SCENES AND USE THEM LIKE GLOBAL FUNCTIONS
BUT PARSING VARIABLES IS NOT THAT SIMPLE, I THEN HAVE TO USE GLOBAL VARIABLES
REAL GLOBAL FUNCTIONS (LIKE A LIBRARY) WOULD BE GREAT !!!
Link to comment
Share on other sites
17 answers to this question
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.