General Programming/Lua question

Home Forums General Programming General Programming/Lua question

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #120464
      • Topics: 6
      • Replies: 12
      • Total: 18

      Heya guys,

      I have been working on my panel for quite a bit now and I’m no programmer so any time I’ve hit a brick wall I’ve just come here for the answers, now progress is coming along but I’m going back over things to tidy up a lot since there are a lot of methods and a lot of messy coding and obsolete code. One thing that I’m unsure how to do that would help with this a lot is – throughout my methods I have “utility” functions (at least thats how I’ll refer to them – nothing to do with the utility features etc in Ctrlr) that are used all over the place in different methods, I just copy and paste them into each script that needs to use it.

      What I’m looking for is how I can have the function declared in one place that I can access from each of my methods without having to have it written out in every other script…Kind of like how in c++ you would have a header file with functions, variables, etc and just #include to reference the functions from it…this stems from just a general lack of understanding of Lua & Ctrlr, (and to an extent programming in general – still pretty n00b).

      for example I have a function for decoding patch/program dumps used in a few places, where ideally I’d have it declared in one file:

      -- utility functions method
      function decodeDump(patchData)
        --my function code


      -- Load patch data method
      function loadPatchData()
        local patchData = {FO, 00, .. F7}
        local decodedData = decodeDump(patchData)

      I assume this is pretty easily doable as it took me an age to realize that I can access non local variables from any method by simply…typing out the variable name. So yeah, any help is appreciated – probably something very obvious or easy to find elsewhere but this forum has proved super helpful so far so it’s pretty much my go to atm.


        • Topics: 4
        • Replies: 480
        • Total: 484
        • ★★

        In the lua editor, Right click on the lua cube and create a function by clicking on Add Method.

        Then you can access that function globally and call it from multiple parts of your panel.

        myRandom = function()
            return (math.random(0, 512))
        a = function()
            local b = myRandom()
            return b + b
        b = function(n)
            if n == true then
                return myRandom()
        console("" .. b(true))


        • This reply was modified 3 years, 1 month ago by dnaldoog.
          • Topics: 6
          • Replies: 12
          • Total: 18

          Sweeeet, thanks again Dnaldoog

        Viewing 3 posts - 1 through 3 (of 3 total)
        • The forum ‘Programming’ is closed to new topics and replies.
        There is currently 0 users and 64 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