Jump to content

Question> return


IIYAMA

Recommended Posts

  • Moderators

I see sometimes the word return in a script, I looked at wiki and I still don't understand why people use it... :shock:

Can somebody explane this part of scripting?

What do I think: It will activate the function again.

Link to comment
function fTest( ) 
    return 1 
end 
  
function fCheck( nValue ) 
    if nValue == 1 then  
        return 'False' 
    end 
    return 'True' 
end 
  
nValue = fTest( ) -- We call function fTest and function return number 1. 
print( 
    fCheck( nValue )  
    --Call function fCheck with argument variable nValue ( number 1 ). 
) 
--> output: False 

You mean it?

Read all comments.

Also what i forgot say.

if you use operator 'return' then you out of function or something.

Example

  
function fMain( ) 
    local nVar = 1 
    if nVar == 0 then 
        return false 
    end 
     
    return true 
end 
  
print( 
    fMain( ) -- Output:true 
) 
  

Also

  
do 
   if true then 
      return 
   end 
   print 'false' 
end 
  

Not output anything.

Edited by Guest
Link to comment
  • Moderators

function fTest( ) 
    return 1 
end 

ftest = 1 right?

nValue = fTest( ) -- We call function fTest and function return number 1. 
print( 
    fCheck( nValue ) 
    --Call function fCheck with argument variable nValue ( number 1 ). 
) 

>

nValue = ftest

and print it.

Link to comment
  • Moderators

So this will happen?

function fMain( ) -- execute function 
    local nVar = 1 -- the value = 1 
    if nVar == 0 then -- check if it has been changed 
        return false -- it will not return to this function 
    end 
    
    return true -- execute function again? 
end 
  
print( 
    fMain( ) -- Output:true -- output ??? 
) 

Link to comment
  
function fMain( ) -- You:execute function I am:Define function 
    local nVar = 1 --  You:the value = 1 I am:Define number variable with value 1 
    if nVar == 0 then --  You:check if it has been changed 
        return false --  You:it will not return to this function I am:It return false. 
    end 
    
    return true --  You:execute function again? I am:It return true 
end 
  
print( 
    fMain( ) --  You:Output:true -- output ??? I am:It output returned value by function fMain. So it output true. 
) 
-- Also i said if you use operator 'return' it quit from function. 
  

Say me if you not understand something.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...