This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Curious about the operation of this script
#1
Hello I have this sample script for the definition and call of functions.

Code:
function max(numero1, numero2)     
   if (numero1 > numero2) then     
      resultado = numero1;        
   else                            
      resultado = numero2;        
   end                            

   return resultado;             --
end

log('El valor máximo de la comparación de dos valores es',max(4,10))
log('El valor máximo de la comparación de dos valores es',max(6,5))
It works perfectly regardless of the order of the numbers passed to the function, it always returns the largest.
I have this other variation.
Code:
max = 4, 10
log('El valor máximo de la comparación de dos valores es', max)

function max(numero1, numero2)     

   if (numero1 > numero2) then     
      resultado = numero1;        
   else
      resultado = numero2;
   end
  return(resultado)
end

Here the problem is that if I change the order of the numbers, the function does not return the highest, it seems that it always returns the first.
What could this be due to? Is the way to call the function and pass it the arguments wrong?
a greeting
Reply
#2
You don't need to create a function for this, just use math.max instead. It accepts any number of arguments, not just 2.

As for your second example, you assign 4 to max variable. 10 is not assigned to any variable. You can assign multiple variables this way but you need to specify them like this:
Code:
a, b = 4, 10
log(a, b)
Reply
#3
Thanks admin for the answer.
The script is only an appearance test for the functions, however thanks for the note from math.max.
Indeed, as soon as I read it, I have noticed what you say, thank you very much.
a greeting
Reply


Forum Jump: