• What does return do?
    6 replies, posted
I saw it in a lua file and wondered what it did. Can anyone help? Thanks PS: Sorry for all of the threads, but I'm trying to learn :)
You should read up on Lua instead of asking lots of questions on the forums. Try reading the [b][url=http://wiki.garrysmod.com/?title=Lua_Tutorial_Series]Lua tutorial series [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b]. [editline]05:41PM[/editline] Some other useful links: [url=http://www.lua.org/manual/5.1/]Lua 5.1 Reference Manual[/url] [url=http://www.lua.org/pil/]PIL[/url]
I read all of the lua syntax tutorials and some of the others on there, but they didn't include some things and I can't find out about them anywhere else :)
For what I know, return is a function for lua files to return a server or clientside information to the script. I'm not sure how to describe it, though.
Return breaks from the current function and returns to where the function was called. Any values/variables listed after the return get returned as well, being stored in variables listed before the function call. [lua]function func() return 1, 2, 3 end local a, b, c = func() print(a, b, c) -- output: 1 2 3 [/lua]
Basically return is communicating from function to where it's called. Eg. [lua]function aFunc() return "Hi"; end Msg( aFunc() ); [/lua] Would print "Hi" to the console. return is used in some garry-defined functions, eg. here's math.Round(): [lua] function math.Round( i ) i = i or 0 return math.floor( i + 0.5 ) end [/lua] It also prematurely ends a function. eg: [lua] function aFunc() return; Msg( "This will not be printed" ); end[/lua]
Hmm still not quite sure what you mean, but thanks.
Sorry, you need to Log In to post a reply to this thread.