Variables


local tw, th = surface.GetTextSize("Mintyy")

Does it set the two variables to the same thing or?

The first is set to the width and the second is set to the height.

Does this only work with specific functions which return 2 variables?

Any function can be written to return multiple values like that. For GetTextSize to work though, you need to first set the font that will be used ( surface.SetFont ); “Mintyy” would be the actual text being measured.

I use that method all the time for certain helper functions that can serve more than one purpose ( for example DistanceTrace returns distance first then the trace used in case other elements are needed, but using it in an if statement will only look at the first if used as such: if ( _p:DistanceTrace( _endpos ) < SOME_DISTANCE ) then … end )


function test( )
	// Separate using comma
	return 123, 456, 789, true;
end

// And how to access them:
local _first, _second, _third, _bool = test( );

No, you can also do something like this
[lua]local var1, var2 = 1, 2[/lua]

That’s the same thing as
[lua]local var1 = 1
local var2 = 2[/lua]
Yes, your example will only work correctly if the function returns 2 variables. If you specify more variables than there are return values for the function, then the extra variables will be nil.