Jump to content

question


001

Recommended Posts

addEventHandler( "onClientPlayerSpawn", root, 
    function ()
	         outputChatBox( getPlayerName(source).." Has Spawned " )
	        	end		 
				)
	

 This is the script 

i want ask about something nothing will occur if i Repaced "End" with ")" like this and why the codes in this arrangement ?

)
end
addEventHandler( "onClientPlayerSpawn", root, 
    function ()
	         outputChatBox( getPlayerName(source).." Has Spawned " )
	        )
			end 
			
	

instead of this

end
)
addEventHandler( "onClientPlayerSpawn", root, 
    function ()
	         outputChatBox( getPlayerName(source).." Has Spawned " )
	        end
			) 
			
	

 

  • Like 1
Link to comment
12 hours ago, Mr.Loki said:

"(" can only be closed by another ")"

function( ) can only be closed by an end

You can't do:

(end

Or

function ( ))

you didn't understand 

i mean why i cant close "(" first before closing the function

" putting ( first then putting end in the second line "

  • Like 1
Link to comment

Because the function is inside the (), if you close the () before closing off the function, it will complain about syntax error, it just won't go further on searching for the first end. That is LUA syntax and cannot be changed in any way.

Link to comment

@Sia Because addEventHandler is a function and you're writing the function within it. The argument in addEventHandler requires a function. You can either add a reference to your function or you can directly write your function as the argument.

function printMessage()
    outputChatBox(getPlayerName(source).." Has Spawned")
end
addEventHandler("onClientPlayerSpawn", root, printMessage) -- put the function in here

Or you could write it directly like so:

addEventHandler( "onClientPlayerSpawn", root, function() -- write the function here directly
	outputChatBox( getPlayerName(source).." Has Spawned " )
end)

-- or

addEventHandler( "onClientPlayerSpawn", root, 
	function()
		outputChatBox( getPlayerName(source).." Has Spawned " )
	end
)

-- however you prefer

You see, it's an argument so you have to close the addEventHandler function with a ) .

 

Edited by Tails
  • Like 1
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...