greenday Posted June 12, 2014 Posted June 12, 2014 This is the code: addEvent ( "onPlayerChooseTeam" , true ) addEventHandler ( "onPlayerChooseTeam" , root , function ( teamName ) local team = getTeamFromName ( teamName ) setPlayerTeam ( source , team ) outputChatBox("You changed your GANG to "..getTeamName(team).." Team.", source, 0, 255, 0) end ) The errors I am getting: In line 6: Bad argument @ 'getTeamName' In line 6: attempt to concatenate a boolean value The argument 'team' of getTeamName is defined above as a local variable but still its a bad argument? And I dont understand what "attempt to concatenate a boolean value" means! I am pretty new to scripting, so please help!
xXMADEXx Posted June 12, 2014 Posted June 12, 2014 Try this: addEvent ( "onPlayerChooseTeam" , true ) addEventHandler ( "onPlayerChooseTeam" , root , function ( teamName ) if ( not teamName ) then return end local team = getTeamFromName ( teamName ) if ( not team ) then return end setPlayerTeam ( source , team ) outputChatBox("You changed your GANG to "..getTeamName(team).." Team.", source, 0, 255, 0) end )
Moderators Citizen Posted June 13, 2014 Moderators Posted June 13, 2014 And I dont understand what "attempt to concatenate a boolean value" means! First you need to know what concatenation is: String concatenation is the operation of joining two character strings end-to-end. For example, the concatenation of "snow" and "ball" is "snowball". outputChatBox("snow".."ball") --prints "snowball" local str = "ball" outputChatBox("snow"..str) --prints "snowball" as well local str = false -- false and true are booleans outputChatBox("snow"..str) -- Error: attempt to concatenate a boolean value You cannot concatenate a boolean value to a string (so true or false) But you can convert this value to a string by using tostring(myValue): local str = false outputChatBox("snow"..tostring(str)) -- prints "snowfalse" According to the wiki page of getTeamName, this function returns false if the 1st argument was not a valid team. So the problem comes from teamName which is not a valid team name. Try to print it to see what you get and if you can fix the problem yourself, please show us the function that triggers that event. You should find something like: triggerEvent("onPlayerChooseTeam", ... (This event might be called from client side, so maybe triggerClientEvent instead.) (Is this event coming from another resource ? If yes, then please give us the link.) I hope my explainations was clear, simple and helpful. 1
greenday Posted June 14, 2014 Author Posted June 14, 2014 Oh yes, thanks for the detailed explanation. I understand the concept clearly now.
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