Jump to content


Photo

mote files, can we pick and choose?


Best Answer Motenten , 16 September 2014 - 05:27 AM

Hmm.  Unfortunately, the functions you mention do depend a bit on some variables that are defined in various scattered places.  I should reorganize that a bit.

 

On the other hand, if  you define the variables that it uses yourself (copy the gear.* stuff from Mote-Include and Mote-Globals), then you can just include Mote-Utility and use those functions (actually, only one function that you'd need to call, set_elemental_gear(spell), calls all the other functions to make everything get set up).

 

Aside from that, I do try to make sure that Mote-Utility functions are completely independent of any other includes, so that you can use them on their own.

Go to the full post


    5 replies to this topic

    #1 Gukai

    Gukai

      Advanced Member

    • Members
    • PipPipPip
    • 95 posts

      Posted 15 September 2014 - 10:35 PM

      Hi 

      I have been in the process of writing my own lua's for a while, converting from xml.  It's slow going because I'm trying to learn lua as I go, and trying to incorporate certain xml abilities into my luas so that I'm not missing/losing any functionality.  

       

      When I was using spellcast I never used any of the include files.  I have continued with the same approach with Lua.  I understand that their purpose is to eliminate the repetition of certain rules, to have them located in 1 place rather than having to copy/paste them in each and every lua we make.  I never looked at the xml include file so I have no idea what was in it, but I did look at the Mote-Include.lua and it was pretty much greek.  Way too advanced for me at this juncture.

       

      I came across the Mote-Utility.lua though, as I'm trying to find the rules related to day/night items so I can utilize my Fenrir's earring.  I was looking through this Utility and while I understand the intent of the rules and could roughly follow them, some of it was new to me.  For example 

      local world_elements = S{world.day_element}
      

      I'm not familiar with any of this coding, such as 'local' and s{world.day_element), but I understood the rule as a whole.  Similarly I recognize that s{world...} is similar in structure to T{'Idle',Resting'} that exist in my current code and although I dont know what it means I get what it does.

       

      Long story short, is it possible to use this Utility file and not the other Mote-files?  I'm not sure if all files are linked to each other and prevent this or not.  I'm not sure if certain part of rules such as 'local' and other stuff does or needs (such as additional supporting files), but I'm trying to learn so I can write my lua's with greater intelligence.

       

      Thanks for anyone's input.



      #2 Arcon

      Arcon

        Advanced Member

      • Windower Staff
      • 1189 posts
      • LocationMunich, Germany

      Posted 16 September 2014 - 05:15 AM

      I came across the Mote-Utility.lua though, as I'm trying to find the rules related to day/night items so I can utilize my Fenrir's earring.  I was looking through this Utility and while I understand the intent of the rules and could roughly follow them, some of it was new to me.  For example 

      local world_elements = S{world.day_element}
      

      I'm not familiar with any of this coding, such as 'local' and s{world.day_element), but I understood the rule as a whole.  Similarly I recognize that s{world...} is similar in structure to T{'Idle',Resting'} that exist in my current code and although I dont know what it means I get what it does.

       

      The "local" keyword restricts a variable to a certain function. Look at this:
       

      foo = function()
          x = 3
      end
       
      foo()
       
      print(x)

       

      This will print "3", because you called the function "foo", which sets x to 3. Now look at this:

       

      foo = function()
          local x = 3
      end
       
      foo()
       
      print(x)

       

      This will print "nil", because x was marked "local" to that function. So it does not exist outside of that function anymore. Once the function finished running, "x" will be whatever it was before the function. Here is another example:

       

      foo = function()
          local x = 3
          print(x)
      end
       
      x = 2
       
      foo()
       
      print(x)
       
      This prints first "3" then "2", because the x inside the function is set to 3, and the one after the function is back to its previous value "2" again. So a local variable is like a completely new variable.
       
      As a rule of thumb, you should always use "local" unless you explicitly want your variable to be shared across multiple functions.
       
      As for the "S{bla}" thing... in Lua, a you define a table by using curly braces. A table is (as you hopefully know by now) just a collection of values. Like the following:
      t1 = { } -- Empty table
      t2 = { 1, 2, 3 } -- Table containing 3 numbers
      t3 = { main = "Mandau", head = "Hecatomb Cap +1" } -- Table containing 2 strings ("Mandau" and "Hecatomb Cap +1", that are being attached to the string keys "main" and "head"
       
      Now we added a way to modify tables a bit. For example, the "T{bla}" thing creates a table just like the regular "{}" does, but the table has a few special properties. The same goes for "S{}", but with different properties. The rule of thumb is: if you have a collection of unique values for which the order doesn't matter, use "S{}", if the order is important use "L{}", otherwise use "T{}".
       
      So in your case ("T{'Idle', 'Resting'}") you should switch to "S{}". The "S" in that stands for "set", because it models a mathematical set.
       

      Long story short, is it possible to use this Utility file and not the other Mote-files?  I'm not sure if all files are linked to each other and prevent this or not.  I'm not sure if certain part of rules such as 'local' and other stuff does or needs (such as additional supporting files), but I'm trying to learn so I can write my lua's with greater intelligence.

       

      I'm not sure I'm afraid (I have notified Motenten to this post, he will know for sure).



      #3 Motenten

      Motenten

        Newbie

      • Members
      • Pip
      • 1 posts

        Posted 16 September 2014 - 05:27 AM   Best Answer

        Hmm.  Unfortunately, the functions you mention do depend a bit on some variables that are defined in various scattered places.  I should reorganize that a bit.

         

        On the other hand, if  you define the variables that it uses yourself (copy the gear.* stuff from Mote-Include and Mote-Globals), then you can just include Mote-Utility and use those functions (actually, only one function that you'd need to call, set_elemental_gear(spell), calls all the other functions to make everything get set up).

         

        Aside from that, I do try to make sure that Mote-Utility functions are completely independent of any other includes, so that you can use them on their own.



        #4 Gukai

        Gukai

          Advanced Member

        • Members
        • PipPipPip
        • 95 posts

          Posted 16 September 2014 - 06:09 AM

          Awesome, thank you both.  I have some carpet being installed so I'll have limited access Wed/Thur.  Afterwards I'll be able to dig deeper into the Utility.  I may need some more help Arcon on understanding that, but I could only give it a quick view since the wife is going to sleep.  Hopefully taking more time later will let it sink in  :)  Nite



          #5 sdahlka

          sdahlka

            Advanced Member

          • Members
          • PipPipPip
          • 324 posts

            Posted 16 September 2014 - 02:11 PM

            Arcon you did forget to say that

             

            foo =function() is equal to function foo()



            #6 Arcon

            Arcon

              Advanced Member

            • Windower Staff
            • 1189 posts
            • LocationMunich, Germany

            Posted 16 September 2014 - 02:17 PM

            I hate the second version and no one should be using that ever :\ Lua is stupid for even allowing it.






            1 user(s) are reading this topic

            0 members, 1 guests, 0 anonymous users