001 Posted May 11, 2017 Share Posted May 11, 2017 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 ) 1 Link to comment
pa3ck Posted May 11, 2017 Share Posted May 11, 2017 Why do you expect LUA to accept broken syntax? Of course it won't work, that is not the correct syntax. 1 Link to comment
Mr.Loki Posted May 11, 2017 Share Posted May 11, 2017 "(" can only be closed by another ")" function( ) can only be closed by an end You can't do: (end Or function ( )) Link to comment
001 Posted May 12, 2017 Author Share Posted May 12, 2017 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 " 1 Link to comment
pa3ck Posted May 12, 2017 Share Posted May 12, 2017 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
Tails Posted May 12, 2017 Share Posted May 12, 2017 (edited) @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 May 12, 2017 by Tails 1 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