Jump to content

Error


murilo2929

Recommended Posts

148/5000

I have a car customization system, and when I enter the marker to customize some elements of the hud do not appear and these errors happen:

7JO3iSG.png

Part of the code that contains error 867

addEventHandler("onClientKey", root, function(key, pressed)
	if panelState and enteredVehicle then
		if pressed then
			if key == "arrow_d" and not promptDialog["state"] and tuningCompleted then
				arrowFel = false
				--[[if szorzas <= maxRowsPerPage then
					szorzas = szorzas + 1
				else
					szorzas = maxRowsPerPage
				end]]
				if #loopTable <= 4 then ---  867 line
					if szorzas ~= 4 then
						lastTick2 =getTickCount()
					end
				end
				if #loopTable > 4 then
					if szorzas ~= 8 then
						lastTick2 =getTickCount()
					end
				end
				if hoveredCategory > #loopTable or hoveredCategory == #loopTable then
					hoveredCategory = #loopTable
				else
					if hoveredCategory > maxRowsPerPage then
						currentPage = currentPage + 1
					end

					hoveredCategory = hoveredCategory + 1

Function that appear the 1988 error

function formatNumber(amount, spacer)
	if not spacer then
		spacer = ","
	end

	amount = math.floor(amount) --- 1988 error line

	local left, num, right = string.match(tostring(amount), "^([^%d]*%d)(%d*)(.-)$")
	return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. spacer):reverse()) .. right
end

what can be?

Link to comment
32 minutes ago, murilo2929 said:

weird because looptable exist

I don't want to be the guy to spot the obvious, but:

in Lua, loopTable is a different variable than looptable because variable names are case-sensitive.

Could you make sure you spelled "looptable" correctly in your code? :)

---

About the second error, I cannot decipher the cause because you are not showing the code that called the function "formatNumber".

Link to comment

so I was checking everything here and I realized that if I change "amount" to some number it works all but there is only that number.

function formatNumber(amount, spacer)
	if not spacer then
		spacer = ","
	end

	amount = math.floor(100) --- I edited the amount to 100 and now it works but the prices are all 100 (aesthetically).

	local left, num, right = string.match(tostring(amount), "^([^%d]*%d)(%d*)(.-)$")
	return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. spacer):reverse()) .. right
end

 

Link to comment
3 hours ago, murilo2929 said:

so I was checking everything here and I realized that if I change "amount" to some number it works all but there is only that number.


function formatNumber(amount, spacer)
	if not spacer then
		spacer = ","
	end

	amount = math.floor(100) --- I edited the amount to 100 and now it works but the prices are all 100 (aesthetically).

	local left, num, right = string.match(tostring(amount), "^([^%d]*%d)(%d*)(.-)$")
	return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. spacer):reverse()) .. right
end

 

Dear murilo2929,

1) either "fix" the code by using the following function:

function formatNumber(amount, spacer)
	if not spacer then
		spacer = ","
	end
  	if not amount then
		amount = 0
	end

	amount = math.floor(amount)

	local left, num, right = string.match(tostring(amount), "^([^%d]*%d)(%d*)(.-)$")
	return left .. (num:reverse():gsub("(%d%d%d)", "%1" .. spacer):reverse()) .. right
end

2) or post your entire code as attachment so we can search for the formatNumber error.

- Martin

Edited by The_GTA
disambiguation
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...