Jump to content

Question> return


IIYAMA

Recommended Posts

  • Moderators
Posted

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.

Posted (edited)
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
  • Moderators
Posted (edited)

Yes I mean that. How does it work lol. I am sorry but this is something that makes me :?

Read all comments.

I did. But still.

Edited by Guest
  • Moderators
Posted

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.

Posted
function fTest( ) 
    return 1 
end 

ftest = 1 right?

Function fTest return number value 1.

P.S I update last post.

  • Moderators
Posted

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 ??? 
) 

Posted
  
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.

  • Moderators
Posted

Thank you for your help Kenix.

I understand it totaly :D

I have get a PM from Solidsnake about "doubleposting" at this topic, so I think I will end it at here.

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...