..:D&G:.. Posted February 15, 2015 Share Posted February 15, 2015 I keep getting this error when I try to get the text from a grid list I get this error: Attempt to perform arithmetic on upvalue "bankBalance" (a nil value) if (not wrong) then if (money ~= nil) and (tonumber(amount) <= money) then if (tonumber(amount) > 0) then local bankBalance = guiGridListGetItemText(accountList, selectedRow, 3) bankBalance = "$".. tostring( bankBalance + amount ) Any ideas guys? Thanks. Link to comment
Callum Posted February 15, 2015 Share Posted February 15, 2015 I'd assume that no row is selected in the grid list. Before line 5 you need to check bankBalance actually has a value, and isn't nil (as the error states). Link to comment
Noki Posted February 17, 2015 Share Posted February 17, 2015 local row = guiGridListGetSelectedItem(gridList) if row ~= -1 and row ~= false and row ~= nil then -- Code, do what you like end Link to comment
Deepu Posted February 17, 2015 Share Posted February 17, 2015 if (not wrong) then if (money ~= nil) and (tonumber(amount) <= money) then if (tonumber(amount) > 0) then local bankBalance = guiGridListGetItemText(accountList, selectedRow, 3) bankBalance = "$".. tostring( bankBalance + amount ) bankBalance is a string right? you have to first convert it to a number token, then you have to do the respective arithmetic operations. you cant do arithmetic operations with a string. So, try using tonumber( ) and try to convert the bankBalance to a number first.. If it still doesnt work then pls tell. Btw you can check if its a number.. using the same tonumber () Link to comment
..:D&G:.. Posted February 17, 2015 Author Share Posted February 17, 2015 I found the problem. I was getting the value from a grid that was previously destroyed, and not from the guy that is visible Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now