Jump to content


Photo

Lua 'and' function?


Best Answer Gukai , 14 September 2014 - 04:49 AM

oh son of a... damn typo... i was looking at the 2nd half of the  rule for typos and not the first!!   /headdesk   ty!!!

Go to the full post


    10 replies to this topic

    #1 Gukai

    Gukai

      Advanced Member

    • Members
    • PipPipPip
    • 95 posts

      Posted 13 September 2014 - 06:55 AM

      Hi

      There is something wrong with this:

       
      function self_command(command)
      	if command == 'toggle TP set' then
      		if sets.aftercast.TP == sets.engaged.TPnormal then
      			sets.aftercast.TP = sets.engaged.TPacc and sets.aftercast.Ranged = sets.midcast.ranged.TPacc
      			send_command('@input /echo ACC SET')
      		elseif sets.aftercast.TP == sets.engaged.TPacc then
      			sets.aftercast.TP = sets.engaged.TPnormal and sets.aftercast.Ranged = sets.midcast.ranged.TPnormal
      			send_command('@input /echo NORMAL SET')
      		end
      	end
      end
      

      I get the message: unexpected symbol near the '='    this is related to the 4th line:

      sets.aftercast.TP = sets.engaged.TPacc and sets.aftercast.Ranged = sets.midcast.ranged.TPacc
      

       

      Anything stand out?  I'm thinking it doesnt like 'and'?

       



      #2 Gukai

      Gukai

        Advanced Member

      • Members
      • PipPipPip
      • 95 posts

        Posted 13 September 2014 - 06:56 AM

        ignore the numbering of the lines too, didnt do what i expected lol



        #3 sdahlka

        sdahlka

          Advanced Member

        • Members
        • PipPipPip
        • 324 posts

          Posted 13 September 2014 - 08:12 AM

          if you really wanted to do the above do it like this
           
          function self_command(command)
              if command == 'toggle TP set' then
                  if sets.aftercast.TP == sets.engaged.TPnormal then
                      sets.aftercast.TP = sets.engaged.TPacc
                      sets.aftercast.Ranged = sets.midcast.ranged.TPacc
                      send_command('@input /echo ACC SET')
                  elseif sets.aftercast.TP == sets.engaged.TPacc then
                      sets.aftercast.TP = sets.engaged.TPnormal
                      sets.aftercast.Ranged = sets.midcast.ranged.TPnormal
                      send_command('@input /echo NORMAL SET')
                  end
              end
          end
           
          but there are better ways to do this
          but i would take a rewrite of your code to do it
          here
           
          set_type = {'Normal','Acc'}
          set_number = 1
          sets.aftercast.TP = {}--leve blank
          sets.aftercast.TP.normal = {}--put your tp normal set here
          sets.aftercast.TP.acc = {}--put your tp acc set here
          sets.aftercast.Ranged = {}--leve blank
          sets.aftercast.Ranged.Normal = {}--put your Ranged normal set here
          sets.aftercast.Ranged.Acc = {}--put your Ranged acc set here
          
          function self_command(command)
              if command == 'toggle TP set' then
                  set_number = (set_number % #set_type)+1
                  send_command('@input /echo '..set_type[set_number]..' SET')
              end
          end
          
          to equip the sets use
          equip(sets.aftercast.TP[set_type[set_number]])
          equip(sets.aftercast.Ranged[set_type[set_number]])
           
          and should you ever need to add more set typs
          add the sets and also
          edit
          set_type = {'Normal','Acc'} exaple: set_type = {'Normal','Acc','Tpgain'}
          sets.aftercast.TP.Tpgain = {}--put your tp tpgain set here
          sets.aftercast.Ranged.Tpgain = {}--put your ranged tpgain set here

          #4 Arcon

          Arcon

            Advanced Member

          • Windower Staff
          • 1189 posts
          • LocationMunich, Germany

          Posted 13 September 2014 - 11:06 AM

          The "and" statement does not work that way. It does not link successive statements together, but it just returns the logical combination of having two non-false values. It is only used in boolean logic (like in an if-statement), and sometimes as a ternary conditional, although that is more advanced and will not usually concern you.

           

          You can adjust sdahlka's suggestion to include sets.aftercast.TP.current and always set the value inside the self_command function. That way you don't have to write equip(sets.aftercast.TP[set_type[set_number]]) but can instead just do equip(sets.aftercast.TP.current). But imo your solution is not bad to have the values elsewhere and not in the same namespace (sets.aftercast.TP for example), that makes most sense when assembling your rules and does not require you to think about the set_type and set_number everywhere you use it.



          #5 Gukai

          Gukai

            Advanced Member

          • Members
          • PipPipPip
          • 95 posts

            Posted 13 September 2014 - 04:35 PM

            Cool, thank you both.  I'm trying not to have too much thought in it, so it's easily adaptable and usable even by a novice.  Much appreciated for your inputs.  I figured since 'or' was usable I could get away with 'and', haha.  Thanks!



            #6 Arcon

            Arcon

              Advanced Member

            • Windower Staff
            • 1189 posts
            • LocationMunich, Germany

            Posted 13 September 2014 - 05:04 PM

            "or" isn't usable in this context either :) They're both only for boolean expressions (or ternary conditionals).



            #7 sdahlka

            sdahlka

              Advanced Member

            • Members
            • PipPipPip
            • 324 posts

              Posted 13 September 2014 - 08:58 PM

              arcon i think he was thinking of something like this

              Usestaff = (Usestaff=='Atk' and 'Acc' or 'Atk')

              but what this is Usestaff = (Usestaff=='Atk' and 'Acc' or 'Atk') is short hand for this
               

              if Usestaff == 'Atk' then
                  Usestaff = 'Acc'
              elseif Usestaff ~= 'Atk' then
                  Usestaff = 'Atk'
              end

              or even this
              Changestaff = not Changestaff

              which tells Changestaff to not be Changestaff

              i.e.
               

              if Changestaff ~= false then
                  Changestaff = false
              elseif Changestaff ~= true then
                  Changestaff = true
              end

              then there is this one that a little more complicated

              stopskill_count = (stopskill_count % #stopskilltyp) + 1

               

              this one tells lua to get the remainder between stopskill_count and #stopskilltyp the +1

              the complicated part is that #stopskilltyp counts how many thing are in the table stopskilltyp(thats what # does)



              #8 Gukai

              Gukai

                Advanced Member

              • Members
              • PipPipPip
              • 95 posts

                Posted 13 September 2014 - 10:50 PM

                This one is bugging me at the moment... its not cycling through

                 

                function self_command(command)
                	if command == 'toggle TP set' then
                		if sets.aftercast.TP == sets.engaged.TPnormal then
                			sets.aftercast.TP = sets.engaged.TPacc
                			send_command('@input /echo ACC SET')
                		elseif sets.aftercast.TP == sets.engaged.TPacc then
                			sets.aftercast.TP = sets.engaged.TPtreasure
                			send_command('@input /echo TREASURE SET')
                		elseif sets.aftercast.tp == sets.engaged.TPtreasure then
                			sets.aftercast.TP = sets.engaged.TPnormal
                			send_command('@input /echo NORMAL SET')
                		end
                	end
                end
                

                it goes from normal to acc to treasure, but its not cycling back to normal  ><

                 

                I am wondering, and havent tried yet, if my others cycle back to the beginning.  i thought they did, which is why this one is baffling me



                #9 sdahlka

                sdahlka

                  Advanced Member

                • Members
                • PipPipPip
                • 324 posts

                  Posted 13 September 2014 - 11:42 PM

                  This one is bugging me at the moment... its not cycling through

                   

                  function self_command(command)
                  	if command == 'toggle TP set' then
                  		if sets.aftercast.TP == sets.engaged.TPnormal then
                  			sets.aftercast.TP = sets.engaged.TPacc
                  			send_command('@input /echo ACC SET')
                  		elseif sets.aftercast.TP == sets.engaged.TPacc then
                  			sets.aftercast.TP = sets.engaged.TPtreasure
                  			send_command('@input /echo TREASURE SET')
                  		elseif sets.aftercast.tp == sets.engaged.TPtreasure then
                  			sets.aftercast.TP = sets.engaged.TPnormal
                  			send_command('@input /echo NORMAL SET')
                  		end
                  	end
                  end
                  

                  it goes from normal to acc to treasure, but its not cycling back to normal  ><

                   

                  I am wondering, and havent tried yet, if my others cycle back to the beginning.  i thought they did, which is why this one is baffling me

                  in one of my previous posts i already gave you the best option for this



                  #10 Arcon

                  Arcon

                    Advanced Member

                  • Windower Staff
                  • 1189 posts
                  • LocationMunich, Germany

                  Posted 14 September 2014 - 12:31 AM

                  The problem is the second elseif. There you have sets.aftercast.tp instead of sets.aftercast.TP. It's just a typo.

                   

                  in one of my previous posts i already gave you the best option for this

                   

                  That's debatable.



                  #11 Gukai

                  Gukai

                    Advanced Member

                  • Members
                  • PipPipPip
                  • 95 posts

                    Posted 14 September 2014 - 04:49 AM   Best Answer

                    oh son of a... damn typo... i was looking at the 2nd half of the  rule for typos and not the first!!   /headdesk   ty!!!






                    1 user(s) are reading this topic

                    0 members, 1 guests, 0 anonymous users