Jump to content
C4 Forums | Control4

General programming best practices questions


Mr .Flibble

Recommended Posts

Hello all. I'm a professional programmer with 10 years experience in the various mainstream languages (PERL, C#, Java, JavaScript) but I have only a couple of hours experience programming Control4 systems. I've a couple of questions that I'm sure run through the minds of most developers when they first work with a C4 system.

My main query is about code re-use. I haven't found any way that I can make basic functions/macros/scripts that can be reused. It seems like if I want to do anything twice I need to repeat myself, which isn't great for a number of reasons. Is there a way to make a script/macro/function that can executed from various places?

Secondly, so far I have only discovered the GUI drag and drop method of programming. I presume this get converted to some sort of textual programming language at some point. Is it possible to see the resulting textual code and to program in that directly? Or is the only way to make a program by using the GUI?

Thirdly, are scrips always run sequentially/single threadedly? Here is why I ask. Imagine the following program which turns off all lights but turns on light1 if it's night time for 5 minutes at night time and turns light2 for 5 minutes at any time:

- turn off all lights

- if nighttime

-- turn on light1

-- wait 5 minutes

-- turn off light1

- turn on light2

- wait 5 minutes

- turn off light2

If we can do a parallel branch then the program will work as desired. If we cannot then we have to add in more logic to workaround the extra 5 minute delay which occurs at nighttime.

Thanks in advance for any tips. If anyone can recommend any reading material please point me in the right direction.

Link to comment
Share on other sites


1. Code re-use is limited to Copy/Paste. Alternatively, I have created template projects in the past, but I have not done this in a couple years honestly.

2. Programming is only done through the GUI.

3. You can use variable or there is a Macros Agent. I use this when I have a program I want to execute form many locations. Use the macro to create the actions and then trigger the macro from many different buttons. You will need to install the macros agent from the agent tab.

4. If you trigger the script and in the scripts has a 5 minute delay then the script will not execute again until the 5 min delay (or the 1st execution of the script completed fully). However, instead of putting in a delay - trigger a timer (another script) with actions that run as a separate process. mutplie scripts will run simultaneously.

In your example it should be:

Execute turn off all lights from a button (example)

- if nighttime

-- turn on light1

-- start light 1 timer

- turn on light2

- start light 2 timer

When Timer 1 expires (separate script under timers agent set for 5 minutes duration):

-turn off light 1

When Timer 2 expires (separate script under timers agent set for 5 minutes duration):

-turn off light 2

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...