Jump to content

2/test.lua:2 '<name>' expect near '('


Recommended Posts

Hi, please can anyone help me?

 

addComamandHandler ( "playerInTheCar" )
function (getPlayerName)  
local playerInTheCar, vehicle == getPlayerName ( player )
if playerInTheCar then
                       outputChatBox ("Ez .. getPlayerName .. járműve!")
 end

)       

Link to comment

The error you're getting means Lua is expecting a function name on line 2, between function and (getPlayerName). But that's only the currently detected syntax error. There's a lot of other syntax and semantic errors in your code besides that one.

addCommandHandler (which you misspelled as addComamandHandler) takes two arguments, the command name and a function that will handle it. You want to remove the ending bracket on line 1 and replace it with a comma, so that the function on the lower lines is an argument of addCommandHandler.

Secondly, you take as parameter a value that you store in a variable called getPlayerName, thereby overriding the MTA function called getPlayerName with whatever value is sent to this function -- which, as it is a command handler, the parameters are source player and the command on the server side, just the command on the client side, plus extra arguments passed through the command by the player.

Thirdly, on line 3, you attempt to get two returns out of the function getPlayerName which only returns one string.

Fourthly, you never end the function and instead had two end brackets one on the first line and the other on the last line.

Lastly, within the if-block, you create a string containing the text "Ez .. getPlayerName .. járműve!" literally when you likely wanted to concatenate getPlayerName variable between the strings "Ez" and "járműve!"

addCommandHandler ( "playerInTheCar", -- no bracket at the end here
  function (player)  -- anonymous function with corrected parameter name
    local playerName = getPlayerName ( player ) -- corrected return variables
    if playerInTheCar then -- this variable is not set and I am unsure what it was meant to be
      outputChatBox ("Ez ".. playerName .. " járműve!")
    end
  end -- end the anonymous function
) -- end of addCommandHandler arguments

 

Edited by Addlibs
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...