Ending function

Hello,
can I stop function after first “if” succeed?

do I need to use “return”?

  function weapon1f( event )
     if hero.selectedWeapon == 2 then

       weapon1.fill = {  type = "image",  filename = "Images/selected.png" }

       weapon2.fill = {  type = "image",  filename = "Images/notSelected.png" }

       hero.selectedWeapon = 1
     end
     if hero.selectedWeapon == 0 then

       weapon1.fill = {  type = "image",  filename = "Images/selected.png" }

       hero.selectedWeapon = 1
     end
     if hero.selectedWeapon == 1 then

       weapon1.fill = {  type = "image",  filename = "Images/notSelected.png" }

       hero.selectedWeapon = 0
     end
   end

Hi @ConveyedRex7592,

Try use if-elseif statement e.g.

   if hero.selectedWeapon == 2 then
      weapon1.fill = {  type = "image",  filename = "Images/selected.png" }
      weapon2.fill = {  type = "image",  filename = "Images/notSelected.png" }
      hero.selectedWeapon = 1
   elseif hero.selectedWeapon == 0 then
      weapon1.fill = {  type = "image",  filename = "Images/selected.png" }
      hero.selectedWeapon = 1
   end

Have a nice day:)
ldurniat

oh, thanks. :slight_smile:
I don’t know why I didn’t think about this.