Jump to content

Need some help


ThePCGuy

Recommended Posts

Hi there,

Could somebody explain what "return" actually does?

And what it does here:

function randomFunction(x,y,z,d) 
    if ( source ~= localPlayer ) then 
        return 
    end 
  
    if tonumber("".. littleCheck .."") > 1 then 
        if d then 
            if getElementDimension(getLocalPlayer()) == d then 
                createExplosion(x, y, z - 10, 12, false, -1.0, false) 
            end 
        end 
    end 
end 
addEvent("randomFunction",true) 
addEventHandler("randomFuction",getRootElement(),randomFunction) 

Link to comment
It's end the function.

Example :

if isPedInVehicle(source) then return end 

And in your code it's :

If the source does not = the player end the function.

Wrong.

return, the word is actaully saying it. it will return a value.

Lua always adjusts the number of results from a function to the circumstances of the call. When we call a function as a statement, Lua discards all of its results. When we use a call as an expression, Lua keeps only the first result. We get all results only when the call is the last (or the only) expression in a list of expressions. These lists appear in four constructions in Lua: multiple assignment, arguments to function calls, table constructors, and return statements. To illustrate all these uses, we will assume the following definitions for the next examples:
    function foo0 ()  
end                  -- returns no results 
  
    function foo1 ()  
return 'a' 
 end       -- returns 1 result 
  
  
    function foo2 ()  
return 'a','b'  
end   -- returns 2 results 

Like the quote above you can use by foo1:

local chek1 = foo1() -- will return 'a' 

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