Jump to content

[HELP] Arithmetic on a boolean value


..:D&G:..

Recommended Posts

Hello guys, I just found out about this error from debugscript

attempt to perform arithmetic on a boolean value

function updateInventory( ) 
    windows.inventory[2].panes = { } 
    local t = exports.items:get( getLocalPlayer( ) ) 
    if t then 
        for k, v in ipairs( t ) do 
            local image = exports.items:getImage( v.item, v.value, v.name ) 
            local width = dxGetTextWidth( v.name, 1, "clear" ) + 20 
            local height = 10 * ( 3 ) 
            table.insert( windows.inventory[2].panes, 
                { 
                    image = image or ":players/images/skins/-1.png", 
                    onHover = function( cursor, pos ) 
                            local width2 = dxGetTextWidth( v.name, 1, "clear" ) + 5 
                            dxDrawRectangle( pos[1], pos[2], pos[3] - pos[1], pos[4] - pos[2], tocolor( unpack( getKeyState( 'delete' ) and { 255, 0, 0, 63 } or { 255, 255, 0, 63 } ) ) ) 
                            dxDrawRectangle( pos[1] + 64, pos[2] - 32, width2, height, tocolor( 0, 0, 0, 255 ), true ) 
                            dxDrawText( v.name, pos[1] + 110, pos[2] , pos[1] + width, pos[2] - height, tocolor( 255, 255, 255, 255 ), 1, "clear", "center", "center", false, false, true ) 
                        end, 

The error is for this line:

local width = dxGetTextWidth( v.name, 1, "clear" ) + 20 

Can anyone tell me what's wrong please?

Link to comment
  • Moderators

v.name is nil or false or something else invalid. So dxGetTextWidth returns false.

Which means you can't count up 20 at a variable which is false.

You have to check the source of where this value has been created.

Link to comment
  • Moderators

[quote name=..:D&G:..]This is from the MTA Paradise gamemode, any ideas, any one how to fix it?

You can try this to solve the warning.

local width = (dxGetTextWidth( v.name, 1, "clear" ) or 0 ) + 20 

But it is better to edit MTA Paradise and fix it there.

This is only a temporary/not bug free way of doing.

WUT! there is a smiley in your name. O_o

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