declaring and getComponent-better way?

Home Forums General Programming declaring and getComponent-better way?

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #72943
    human fly
    Participant
      • Topics: 124
      • Replies: 1070
      • Total: 1194
      • ★★★★

      please help me abbreviate this: (i’ve forgotten the other forms i’ve seen)

      function tabsToneTimb0_pt1()
      
      	-- This stops issues during panel bootup
      	if panel:getRestoreState() or panel:getProgramState() then return end
      
      --show tab
      	local tab= panel:getComponent ("tabs_toneTimbrePt1"):setPropertyInt("uiTabsCurrentTab", 0)
      	local tabLCD = 	panel:getComponent ("tabs_LCD"):setPropertyInt("uiTabsCurrentTab", 0)
      --reset background colour layer
      	coloursInit()
      
      	--tabsWG
      		tabs_Main_pt1 = panel:getComponent("tabs_Main_pt1"):setVisible(true)
      		tabs_mainB_pt1 = panel:getComponent("tabs_mainB_pt1"):setVisible(true)
      		tabsParamB_p1pt1 = panel:getComponent("tabsParamB_p1pt1"):setVisible(true)
      		tabsParamB_p2pt1 = panel:getComponent("tabsParamB_p2pt1"):setVisible(true)
      		tabsParamB_p3pt1 = panel:getComponent("tabsParamB_p3pt1"):setVisible(true)
      		tabsParamB_p4pt1 = panel:getComponent("tabsParamB_p4pt1"):setVisible(true)
      	--tabs_Patch
      		tabs_Patch = panel:getComponent("tabs_Patch"):setVisible(false)
      	--tabs_Patch = panel:getComponent("tabs_Patch"):setProperty("componentVisibility",0, false)
      	--button led highlight
      	panel:getComponent("tabOnClick_Tone")	:setProperty("uiButtonTextColourOff","FF00FF00", false)
      	panel:getComponent("tabOnClick_Timbre")	:setProperty("uiButtonTextColourOff","FF1291DF", false)
      	panel:getComponent("tabOnClick_Patch")	:setProperty("uiButtonTextColourOff","FF1291DF", false)
      	panel:getComponent("tabOnClick_Rhythm")	:setProperty("uiButtonTextColourOff","FF1291DF", false)
      	panel:getComponent("tabOnClick_Global")	:setProperty("uiButtonTextColourOff","FF1291DF", false)
      end

      i am declaring on panel load with a separate method, with:

      function panelModulators()
      --declare panel operation elements
      -- layer
      	layer0 = panel:getCanvas():getLayerByName("layerGrey")
      	layer1 = panel:getCanvas():getLayerByName("layerRed")
      	layer2 = panel:getCanvas():getLayerByName("layerBlue")
      	layer3 = panel:getCanvas():getLayerByName("layerGreen")
      -- tabs Parameters
      	tabs_Main_pt1 = panel:getComponent("tabs_Main_pt1")			--:setVisible(true)
      	tabs_mainB_pt1 = panel:getComponent("tabs_mainB_pt1")		--:setVisible(true)
      --tabs ParamA
      	tabsParamA_p1pt1 = panel:getComponent("tabsParamA_p1pt1")	--:setVisible(false)
      	tabsParamA_p2pt1 = panel:getComponent("tabsParamA_p2pt1")	--:setVisible(false)
      	tabsParamA_p3pt1 = panel:getComponent("tabsParamA_p3pt1")	--:setVisible(false)
      	tabsParamA_p4pt1 = panel:getComponent("tabsParamA_p4pt1")	--:setVisible(false)
      --tabs ParamB
      	tabsParamB_p1pt1 = panel:getComponent("tabsParamB_p1pt1")	--:setVisible(true)
      	tabsParamB_p2pt1 = panel:getComponent("tabsParamB_p2pt1")	--:setVisible(true)
      	tabsParamB_p3pt1 = panel:getComponent("tabsParamB_p3pt1")	--:setVisible(true)
      	tabsParamB_p4pt1 = panel:getComponent("tabsParamB_p4pt1")	--:setVisible(true)
      --(etc.)
      end
      #72944
      human fly
      Participant
        • Topics: 124
        • Replies: 1070
        • Total: 1194
        • ★★★★

        i tried to do this but it fails at the 1st item. it should be
        declared with the load method. or does it have to be declared
        locally?

        	tabs_Main_pt1:		getComponent():setVisible(true)
        	tabs_mainB_pt1:		getComponent():setVisible(true)
        	tabsParamB_p1pt1:	getComponent():setVisible(true)
        	tabsParamB_p2pt1:	getComponent():setVisible(true)
        	tabsParamB_p3pt1:	getComponent():setVisible(true)
        	tabsParamB_p4pt1:	getComponent():setVisible(true)

        i was hoping to reduce code, and only declare once. what would be the
        correct way to do this?

        #72946
        Puppeteer
        Participant
          • Topics: 16
          • Replies: 185
          • Total: 201
          • ★★

          Maybe try to remove getComponent() from the second set of commands, as you’ve already wrapped that into the variable.

          ie first line should be

          tabs_Main_pt1:setVisible(true)

          The Puppeteer
          http://godlike.com.au

          #72947
          human fly
          Participant
            • Topics: 124
            • Replies: 1070
            • Total: 1194
            • ★★★★

            just tried that now, didn’t like it

            At line [13]: [string "tabsToneTimb0_pt1"]
            
            Error message: [string "tabsToneTimb0_pt1"]:13: attempt to index global 'tabs_Main_pt1' (a nil value)

            strange. could it be because it’s declared as getComponent, and not
            getModulatorByName? even tried:
            tabs_Main_pt1 = panel:getModulatorByName():getComponent("tabs_Main_pt1")

            >definitely didn’t like that: this crashes the panelLoaded method that
            calls the ‘panelModulators’ method.

            >strange: where i have things declared as getModulatorByName, this type
            of call works fine. maybe getComponent is no good for startup declaration?
            – – – –
            as a side-note, what i would like to do here ultimately is combine 5 methods
            into one. i have 5 buttons, and each has a method that 1/sets a tab view, 2/
            changes the button text colour 3/sets another tab view, (etc. if i want more
            stuff to happen)

            these are ‘old’ methods in my panel, with everything declared there.
            although i have a separate ‘panel modulators’ (as opposed to ‘parameter
            modulators’, separate startup declaration method, just to keep things
            readable) it wasn’t/isn’t doing anything, apparently.

            not sure if startup declaration NEEDS to be getModulatorByName,
            rather than just getComponent ? > doesn’t seem to change it anyway.

            #72952
            goodweather
            Participant
              • Topics: 45
              • Replies: 550
              • Total: 595
              • ★★★

              Declaring your variables separately works fine.

              varMod = panel:getModulatorByName(“my_button”) makes varMod representing a modulator.
              You can verify this by typing what(varMod) in the console
              varComp = panel:getModulatorByName(“my_button”):getComponent() makes varComp representing the compoonent within the my_button modulator.
              You can verify this by typing what(varComp) in the console
              It is the equivalent of varComp = varMod:getComponent()

              It is no problem to have several methods into one…
              The OnChange methods have “mod” as variable and this represents the modulator that produced the changes.
              You can track its name or other property then based on if…elseif… statements perform the operation you want.

              I noticed there are issues with SetVisible so you need to handle this differently.

              #72954
              human fly
              Participant
                • Topics: 124
                • Replies: 1070
                • Total: 1194
                • ★★★★

                yes, i have had no problem declaring methods separately elsewhere.
                i will try again later.

                (i’ll start another topic for the buttons)

                #72961
                human fly
                Participant
                  • Topics: 124
                  • Replies: 1070
                  • Total: 1194
                  • ★★★★

                  suddenly found out one of my pre-declaration no longer works,
                  for some reason. checked thoroughly, went back looking at a
                  couple of versions to find the last good one, – and that bit
                  was no different, except it just didn’t work anymore.

                  so i had to put it declared again within the method where it
                  was working anymore in the shorter form that previously worked.

                  at least i was able to fix it – but i didn’t find out what had
                  changed. very strange.

                  i also find i have problems with some start methods not doing
                  their thing when it’s drafted as an exe. not sure what’s happening
                  there, when it works with the panel.

                Viewing 7 posts - 1 through 7 (of 7 total)
                • The forum ‘Programming’ is closed to new topics and replies.
                There is currently 0 users and 83 guests online
                No users are currently active
                Forum Statistics
                Threads: 2,495, Posts: 17,374, Members: 77,605
                Most users ever online was 12 on January 22, 2019 3:47 pm
                Ctrlr