Jump to content

[HELP] Arithmetic on a boolean value


..:D&G:..

Recommended Posts

Posted

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?

  • Moderators
Posted

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.

Posted

It fails to get the width, thus it will return false. You can't do calculations on a boolean(true/false).

With most likeliness the variable v.name is not properly defined or passed through.

  • Moderators
Posted

[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

Posted

I managed to find the problem.

When a player is given an item by the script, it has to have a name/value like "Bank Card" or a name in the database. Now, I am trying to make each script name the items.

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