Jump to content

[Help] attempt to compare string with number


DotFrank

Recommended Posts

Hi guys, i have a problem comparing getPlayerMoney() with price, if i dont use tonumber(price) the error is 'attemp to compare string with number' and if i use tonumber(price) then the error is  'attemp to compare nil with number'.  This problem is only comparing, if I do not use the condition server-side gives me the weapon.

function onBuyWeapon()
	local itemSelected= guiGridListGetSelectedItem(list)
	if itemSelected ~= -1 then
		local weaponName = guiGridListGetItemText (list,itemSelected,column_arma)
		local ammo = guiGridListGetItemText(list,itemSelected,column_balas)
		local price = guiGridListGetItemText(list,itemSelected,column_precio)
		if getPlayerMoney() >= price then
			triggerServerEvent("onBuyWeapon",getLocalPlayer(),weaponName,ammo,price)
		end
	end
end

 

Link to comment
I already used it on server side too, same mistake.
--server-side

if getPlayerMoney(source) >= price then -- attempt to compare string with number. I if use tonumber(price) the error is => attempt to compare nil with number
	giveWeapon(source,weaponID,ammo) -- without the condition it gives me the weapon
end

 

Link to comment

Try this.

if getPlayerMoney(source) >= tonumber(string.sub(price, 2)) then -- attempt to compare string with number. I if use tonumber(price) the error is => attempt to compare nil with number
	giveWeapon(source,weaponID,ammo) -- without the condition it gives me the weapon
end

 

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