Jump to content

convertNumber.


MajdMTA

Recommended Posts

You have the simplest example on the website:

function convertPlayerMoney() 
    local pMoney = getPlayerMoney() --get the players money 
    local convertedMoney = convertNumber(pMoney) --converts it and saves it in variable 
    outputChatBox(convertedMoney) --outputs it 
end 
addCommandHandler("money", convertPlayerMoney) 

You would just have to change the local pMoney to get the value of the vehicle, and that would be it, but if you need more help you can post the code,

Link to comment
     local carCost = guiGridListGetItemText (carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carCost) 
            local carprice = guiGridListGetItemText(carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carprice) 
  
function convertNumber ( number )   
    local formatted = number   
    while true do       
        formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')     
        if ( k==0 ) then       
            break    
        end   
    end   
    return formatted 
end 

So tell me where's the bug?

Link to comment
     local carCost = guiGridListGetItemText (carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carCost) 
            local carprice = guiGridListGetItemText(carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carprice) 
  
function convertNumber ( number )   
    local formatted = number   
    while true do       
        formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')     
        if ( k==0 ) then       
            break    
        end   
    end   
    return formatted 
end 

So tell me where's the bug?

You made the prices in table then loop it ?

Edited by Guest
Link to comment
     local carCost = guiGridListGetItemText (carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carCost) 
            local carprice = guiGridListGetItemText(carGrid, guiGridListGetSelectedItem(carGrid), 2) 
            local convertedMoney = convertNumber(carprice) 
  
function convertNumber ( number )   
    local formatted = number   
    while true do       
        formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1,%2')     
        if ( k==0 ) then       
            break    
        end   
    end   
    return formatted 
end 

So tell me where's the bug?

That has to throw an error since you're trying to call function 'convertNumber' that is nil. It is nil because it wasn't defined yet until few lines later. You have to put the function definition outside of this function (I assume it is a function called by some event handler).

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