Jump to content

Bad Arguments and attempt to concatenate a boolean value


greenday

Recommended Posts

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!

Link to comment

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 ) 

Link to comment
  • Moderators
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.

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