View Single Post
Old 05-11-2019, 02:47 PM   #16
Human being with feelings
tXShooter's Avatar
Join Date: Aug 2017
Posts: 301
Default How do you Short-Hand the Functions?

Taking on the challenge of condensing things down with the usage of tables which Lokasenna introduced me to (thank you), I'm doing a Rev 3 re-write, and I've come across an conundrum. How do you assign functions that are similar, but still different? And conversely, how do you go about writing functions that are unique to each button's usage, yet still generic enough for a smaller script? Would I have to type out each and every function assignment as well as the actual function? (In this version I'm just going to do a total of 20 songs and 20 sermons, each with a Start and Stop button, instead of trying to do the 400 songs/sermons in my Rev 2 (that seriously got to be daunting and chaotic). A) So, am I looking at having to write a total of 80 functions for the 80 total buttons?)

Consider the code below.

When specific conditions are met, ie. all of the textboxes to the left of the 'Scene' textbox have valid information in them, the color for the Start button changes as well as the one to the End button (both to lime). So, when the 'Scene' textbox loses focus, a function validates the information to the three left textboxes and if valid it changes the color of the two buttons to the right. When one clicks on Start Special 1, the button's text should be updated with the position of the marker this button is creating, and its color is changed to a dull red while the other button is set to a bright red. When one clicks on the End Special 1 button, it's text also changes to the position of the marker it creates and changes the color of the buttons.

These functions can also be activated by the OSC input from a mixer console... if the mixer goes into a scene that matches one of the Scene textboxes, it calls the same function as the button that is assigned to that row of textboxes. Upon leaving that scene or manually clicking any other row's start button, the functions to other button are launched. The OSC input is the preferred method of placing a marker, but I need to allow for those manual moments as well.

B) How should I write the functions so that they respond correctly if clicked or OSC-activated out of sequence from the other Start/End Buttons? Can they be written generically and differentiate what called it? I'm still pretty new to Lua programming, so please forgive my ignorance.

{^^^^^ Too much information? ^^^^^}
-- ********** GUI Elements **********************
AllTabsY = {30,55,81,107,133,159}  -- Row Placement Y Values

SongTabCaptions = {"Title","Singer or Group Name(s)","Track(s)","Scn","Manually Edit Markers"}
SongTabsX = { 90, 430, 730, 880} -- Column Placement X Values
SongTabsW = {338, 298, 148,  40} -- Textbox Widths
SongTabsH = 25
MarkerButtonWidth = 110
MarkerButtonHeight = 20

-- Add Song Section to GUI
-- Tab 1 Labels Z = 12 Y = 25
function BuildGUI()
	-- Build Tab 1 Labels
	for i=1,5 do
		GUI.New(SongTabCaptions[i], "Label",{z=21, caption=SongTabCaptions[i], x=SongTabsX[i], y=30, font=2, color="txt",bg="wnd_bg",shadow=false})
	-- Build Tabs 1 and 2 
	local Tab_Index = 1
	local b = 1
	for SongTabs = 1, 2 do -- Add GUI controls to Song Tabs 1 & 2
		local a = 1
		for Y= 1, 5 do -- Add 5 lines of Textboxes and Buttons for Tabs 1 and 2
			for X = 1, 6 do -- Add 4 Textboxes and 2 Buttons on Line 'a'
				GUI.New("SongTitle" .. a, "Textbox", {
				z = 11 + SongTabs
				x = SongTabsX[X], y = AllTabsY[Y],
				w = SongTabsW[X], h = SongTabsH,
				caption = "", cap_pos = "left",
				font_a = 3,	font_b = "monospace",
				color = "txt", bg = "wnd_bg",
				shadow = true, pad = 4,
				undo_limit = 20, tab_idx = Tab_Index
				Tab_Index = Tab_Index + 1})

				GUI.New("Marker_SongStart" .. b, "Button", {
				z = 11 + SongTabs,
				x = 930,  y = AllTabsY[Y],
				w = MarkerButtonWidth, h = MarkerButtonHeight,
				caption = "Start Special " .. a,
				font = 3,
				col_txt = "txt", col_fill = "elm_frame",
				func = StartButtonClick[a]})
				GUI.New("Marker_SongEnd" .. b, "Button", {
				z = 11 + SongTabs,
				x = 1040,  y = AllTabsY[Y],
				w = MarkerButtonWidth, h = MarkerButtonHeight,
				caption = "End Special " .. a,
				font = 3,
				col_txt = "txt", col_fill = "elm_frame",
				func = EndButtonClick[a]})

This is what I WAS doing until this posting helped to simplify several things. Hopefully I can keep simplifying things to a more manageable level.
function GUI.elms.Song1Scene:lostfocus()
	Song1SceneVal = GUI.elms.Song1Scene.retval
	if Song1SceneVal ~= nil or Song1SceneVal ~= "" then
		if ValidateSong1TextBoxes() then
function Song1StartButtonClick()
	Song1SceneVal = GUI.Val("Song1Scene")
	X32Scene = GUI.Val("X32Scene")
How should I go about writing a generic function that does that function for each of the 'Start' buttons?
"But be ye doers of the word, and not hearers only, deceiving your own selves."
tXShooter is offline   Reply With Quote