Moderators IIYAMA Posted March 19, 2012 Moderators Share Posted March 19, 2012 I see sometimes the word return in a script, I looked at wiki and I still don't understand why people use it... Can somebody explane this part of scripting? What do I think: It will activate the function again. Link to comment
Kenix Posted March 19, 2012 Share Posted March 19, 2012 (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 March 19, 2012 by Guest Link to comment
Moderators IIYAMA Posted March 19, 2012 Author Moderators Share Posted March 19, 2012 (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 March 19, 2012 by Guest Link to comment
Moderators IIYAMA Posted March 19, 2012 Author Moderators Share Posted March 19, 2012 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
Kenix Posted March 19, 2012 Share Posted March 19, 2012 function fTest( ) return 1 end ftest = 1 right? Function fTest return number value 1. P.S I update last post. Link to comment
Moderators IIYAMA Posted March 19, 2012 Author Moderators Share Posted March 19, 2012 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
Kenix Posted March 19, 2012 Share Posted March 19, 2012 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
Moderators IIYAMA Posted March 19, 2012 Author Moderators Share Posted March 19, 2012 Thank you for your help Kenix. I understand it totaly I have get a PM from Solidsnake about "doubleposting" at this topic, so I think I will end it at here. Link to comment
Kenix Posted March 19, 2012 Share Posted March 19, 2012 Thank you for your help Kenix. No problem. I'm always glad to help. Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now