Home Forums General Programming do functions inside a method remain 'local'?

This topic contains 3 replies, has 2 voices, and was last updated by  human fly 1 week, 5 days ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #73487

    human fly
    Participant

    (before i check this out)

    if i put a function inside a method, does have a ‘local’ status?
    or will it have the same action (or a conflict) if i use the same
    function name in another ‘twin’ method, doing the same thing to
    different modulators/components?

    or can i specify that a function is local?

    eg:

    structure12 = function (--mod, --value)
    
    -- sets corresponding option views
    
    	local structure =	panel:getModulatorByName("struct12_pt1"):getValue()
    	local SynPcm1 =		panel:getComponent("tabs_SynPcm1_pt1")
    	local SynPcm2 =		panel:getComponent("tabs_SynPcm2_pt1")
    --
    	function see00()
    	SynPcm1:setPropertyInt("uiTabsCurrentTab", 0)
    	SynPcm2:setPropertyInt("uiTabsCurrentTab", 0)
    	end
    
    	if 
    	structure == 0 then see00()
            end
    end

    and then, i would want to use the same code, with a method
    called ‘structure34’, addressing similarly named modulators
    and components, but with names suffixed 3/4 instead of 1/2,
    and keep the same ‘sub’-function names. or would these have
    to now have unique names too?

    ie: once created, do they remain in memory everywhere else
    in the panel, ready to be called? or do they exist only for
    that method?

    #73488
    Puppeteer
    Puppeteer
    Participant

    No it’s not local. Everything is global by default. You need to use local before a variable if you want it defined locally. Not sure if you can make methods local.

    The Puppeteer
    http://godlike.com.au

    #73489

    human fly
    Participant

    (answering own post..)

    well, it seems ok if i just copy the whole thing and amend
    the declarations.

    suppose if i had created them externally in a ‘library’ method,
    and called them from there, there would be an issue (and functions
    would have to check which modulators+components to act on).

    #73492

    human fly
    Participant

    hi Puppeteer, missed your post.
    as i said, it seems ok, repeating the same function/s identically
    within a method –see00(), see01(), see10(), see11()–
    i called them that to indicate which of 2 tabs were showing for
    2 uiTabs. and in each method, they are addressing different
    uitabs (synPcm1+2 pair, and synPcm3+4 pair).

    so i can put ‘local ‘ in front of a ‘sub’-function ?
    done now, and seems to be ok, so i’m leaving it like that for now.

    (as i may end up later with 8 parts, and thus 8x everything – which
    i can avoid once i work it out, no doubt – it makes it easier if
    i can just rename the declarations at the top and leave the rest
    as is (this optimises a couple of methods a lot already).

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.

Comments are closed.