Lua Basics for Ctrlr – Beginners

Home Forums General Programming Lua Basics for Ctrlr – Beginners

Tagged: 

Viewing 20 posts - 21 through 40 (of 49 total)
  • Author
    Posts
  • #71870
    human fly
    Participant
      • Topics: 124
      • Replies: 1070
      • Total: 1194
      • ★★★★

      this looks like a nice reference. well-organised, easy to browse

      https://www.tutorialspoint.com/lua/index.htm

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

        i would like to make a counter that loops. maybe a momentary
        button as an incrementor ( i know there’s inc/dec buttons for
        this, but i’m not getting it to work ) for another parameter.

        every click must add (1) to value of ie: a horiz.fader with 0-9 range,
        and when it reaches 9, it loops round to 0 – or maybe do 0-15/00h-0Fh, etc.

        – – – – – – – – – – – – –
        going to try to use setVisible() to reset some modulator views on load.
        so that means writing a method for ‘when Panel has finished loading’.
        not sure of the format of that – the header is a bit confusing: ‘type’?
        it is referring to ‘instance’, single, multi, etc.
        some explanation of this would be very useful.

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

            just saw:

            “Convention of Names in Lua

            normal variables start with small letters
            functions start with capital letters
            parameter of functions start with an underscore.”

            another Lua tutorial site:

            http://lua.lickert.net/index_en.html

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

              Yep and you can add a Visual Basic flavor as I’m doing in my code by indicating the type of variable in the variable name BUT don’t forget that variables in Lua do not have a type (Integer, float, string…).

              Examples:
              modCutOff as variable having a CutOff modulator assigned to it
              iBank as variable to indicate a bank number
              sBank as variable to indicate a bank name
              PatchInit()
              CutOff_OnChange()
              CutOff_OnClick()

              I’m doing this to remember what I used the variables for as I’m using most of the time global variables that are valid thru all methods (in opposition to local ones that are only valid in the current method) – you raised that question somewhere…

              Once again, not necessary but much more easier to read and maintain your code afterwards 🙂

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

                ah: so local variable is only the current method,
                and global is valid for all methods, throughout the
                project/panel.

                http://lua.lickert.net/variable/index_en.html

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

                  you have to explain this as if you were talking to a 5-yr old,
                  hope you realise.

                  • This reply was modified 6 years, 11 months ago by human fly.
                  #71901
                  human fly
                  Participant
                    • Topics: 124
                    • Replies: 1070
                    • Total: 1194
                    • ★★★★

                    –Called when a button value changes
                    –increment count

                    function increment2(value)

                    local count = panel:getModulatorByName(“count1_8”):getModulatorValue()

                    count = count + 1
                    return count
                    end

                    what is missing? this doesn’t do anything.

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

                      You are not doing anything with the arg “value” so you can remove it.
                      Are you sure count has a value?
                      Insert under the local count= line a console output as:
                      console(tostring(count))

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

                        yes..i have no idea how to use ‘console’.
                        could you explain how i can use it? ie: to reproduce some
                        print exercises etc.

                        tbh, i don’t know if ‘count’ has a value. i just figured that
                        if it is to increment, the parameter’s value should increment.
                        ie: ‘count1_8’ modulator

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

                          not confident with those arguments in brackets yet.
                          this needs some applied practice with the console.

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

                            Anywhere in a method you can add:
                            console(tostring(any_variable))

                            Use tostring() to be sure to convert the variable value to a string because console() accepts only strings.

                            You can also open the Lua console under Panel. In the bottom part you can type any console() statement to check any variable. The result will be displayed in the upper part.

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

                              wait a minute… 🙂
                              i have tried typing in the console.
                              if i type print(“hello world”), i get back exactly that.
                              or rather >>>>print(“hello world”).

                              so i’m doing something wrong there.
                              (lol he can’t even print hello world..)

                              not getting any results there yet.

                              i will try this again.

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

                                side question – available IDs in Ctrlr, this link:

                                https://github.com/RomanKubiak/ctrlr/blob/master/Source/Core/CtrlrIDs.h

                                now, these are all pre-declared variables that can be refered to,
                                is that correct? as i’m seeing things written differently:
                                ie: getValue vs getModulatorValue

                                are these the same thing? and how am i to know what i can use?
                                (sorry, i *will* get it eventually – my focus is a bit scattered
                                by having to take all of this onboard at once.)

                                for instance, at line ~773, we have:

                                DECLARE_ID (luaModulatorValueChange);
                                DECLARE_ID (luaModulatorComponentChange);
                                DECLARE_ID (luaModulatorPropertyChanged);

                                so, are all those starting with ‘lua’ also pre-defined
                                methods one can call? ‘Called when modulator value changes’
                                is referred to as (the better) ‘luaModulatorValueChange’,
                                which i’ve already seen somewhere.

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

                                  this thread is worth a read:

                                  LUA examples


                                  this is where atom is introducing the idea of Lua
                                  in Ctrlr (and talking about fetching parameter dumps
                                  and updating screen controls)

                                  and:

                                  http://www.lua.org/manual/5.1/manual.html#2.1

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

                                    It’s amazing how you are reasoning/working… You try understanding complex stuff, you search in complex stuff but without mastering easy stuff first…
                                    I would advise you to limit yourself to easy stuff, get a simple thing working then if needed, extend further from there…

                                    About console, just apply what I said above, it does what I described…
                                    – let’s say that in your code you have iBank = 12
                                    – if you add a line console(tostring(iBank)) in the code you will see 12 in the console window
                                    – if your panel is open and that you ran different things then you can open the console window and type a console statement in the bottom part to check the value of any global variable used in the code

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

                                      ok, i’ve got an idea :o)

                                      could you just post a whole thing i can paste into the console,
                                      just to see how it works. that’ll be quicker than me figuring out
                                      what the form of that should be. 🙂

                                      – – –
                                      yes, i need to get the basics down. that’s why i’m trying to figure
                                      this out .. the links i’m posting, don’t worry about that, i’m just
                                      putting things here as i find them, if they seem relevant, …in the
                                      overall picture … (…)

                                      what i would really like to do today… is ..increment
                                      the a=a+1 thing .. and how, for instance, i might click a
                                      momentary button modulator, to increment the value of
                                      another modulator, ie: a slider. that seems like it is a
                                      basic operation.

                                      there are a couple of examples i’ve found in other panels.
                                      i can try to copy the form and see what works.
                                      (still not mastered the console for what i would like to do)

                                      • This reply was modified 6 years, 11 months ago by human fly.
                                      #71913
                                      proton
                                      Participant
                                        • Topics: 19
                                        • Replies: 94
                                        • Total: 113
                                        • ★★

                                        Hi human fly,

                                        yet again you are asking for a ready to go code while at the same time you say yourself you don’t get the difference between a local or global variable or some other basic stuff in general.
                                        And yet again another user is pointing out to you that maybe you take things too fast or from the wrong angle (too complicated concepts for starters).

                                        Also you have this habit of posting every thought that comes to your mind while you are in the process of learning and while this might be a good way for you to store/record your learning process I’m not really sure if this helps other users and is not just cluttering the forum in a way.
                                        Maybe some other users will chime in and comment on that subject. I would like to know what other think about this.
                                        Cheers!

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

                                          Totaly agree with you Proton!
                                          If I would put in the forum all my issues / thoughts / prototypes / failures with Ctrlr I would be busy typing in the forum instead of thinking about solutions 😉

                                          human fly, now don’t take it too strong but indeed you should limit your posts and post/ask somehting only after having done a thorough search / try of different ways of working. In programming there are always different ways to reach the same goal and when one is not working the fun is just to avoid the obstacel and to search for a workaround. Programming would not be so thrilling if it would be too easy…

                                          Here for Ctrlr, you have plenty of panels and also forum topics to look at and use in your own panel before having the need to request things.

                                          And for all, now that I released my Pro2 panel, I’m adapting it to Prophet 12 with some other users and I’m also rewriting/completing the step by step guide.

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

                                            you’ve got the wrong idea.

                                            ok: look: point taken. i will endeavour to be more
                                            economical with volume of text. other than that,
                                            i don’t see a problem with asking elementary
                                            questions in a topic called ‘beginners’. i’m going to
                                            restrict my activity to asking questions here, how
                                            about that? then, if you don’t want to read it, you
                                            don’t have to look at it or subscribe to it. if,
                                            however, there are people who want to discuss these
                                            things, then please do follow it, because i want to
                                            talk about some fundamentals at this stage. if i’m
                                            working on ctrlr every day, then i don’t think it’s
                                            over the top to post once a day. and i’m posting links
                                            to example panels, with my methods in them, to
                                            illustrate – if you weigh that up against you saying
                                            i’m ‘asking for readymade code’..you said that before
                                            and i wasn’t.

                                            now: i can’t make sense of Goodweather’s answer. i’m
                                            not asking for ready-written code. just some thing
                                            i can paste in and go ‘ah ok, so that’s what it looks
                                            like’. rather than farting around for hours getting
                                            nowhere. ie: i’m not getting the console working,
                                            what’s wrong?

                                            practising things in the console seems to be the
                                            next step at this stage. i’m just doing simple stuff,
                                            things i can recognise and work and learn from.

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