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?

76561198066470453.png

SP37Ecj.jpg?2MTA:Rust Pre-Alpha Build v.0.3:SP37Ecj.jpg?2

https://forum.mtasa.com/viewtopic.php?f=114&t=97848

2Pac: ''Only God can judge me!''

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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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.

If I help you in a thread and you need further assistance, please don't PM me - use the thread you created instead. This way everyone on the forum can take advantage of it.

  • 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

Do you want to improve your Lua programming skills and make less mistakes?   Start with Lua Language Server!   🙀

 

  Useful functions  3x 

  Tutorials  4x 

 

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