Jump to content

[HELP] Attempt to do arithmetic on a nil value


Kazafka

Recommended Posts

 Attempt to do arithmetic on a nil value. And the code is:

--Here you have the tables
playersT = {"VaporZ"}
moneyT = {"100"}

addCommandHandler("deposit", function(player, commandName, amount) --Here is our "nil" value (I often use "100" for "amount", when I have $12,000)
	for k, v in ipairs(playersT) do
		if(string.match(playersT[k], getPlayerName(player))) then
			if amount and (tonumber(amount) <= getPlayerMoney(player)) then
				local i = table.find(players, getPlayerName(player))
				local am = tonumber(amount) --Setting "am" as "amount", but changed into number
				takePlayerMoney(player, am) --Here's everyting ok
				moneyToLow = tonumber(moneyT[i]) - am --But here is a problem with "am" IDK why ("Attempt to do arithmetic on a nil value")
				moneyT[i] = tostring(moneyToLow)
				outputChatBox ("#09ff00Transfered into bank account #ffffff$" .. amount .. "#09ff00!", player, 255, 255, 255, true)
			end
		elseif(not string.match(playersT[k], getPlayerName(player))) then
			local size = table.size(playersT)
			local i = size + 1
			playersT[i] = getPlayerName(player)
			moneyT[i] = amount
			takePlayerMoney(player, tonumber(amount))
			outputChatBox ("#09ff00Transfered to bank account #ffffff$" .. amount .. "#09ff00!", player, 255, 255, 255, true) 
		end
	end
end)

I will say only one thing - What The *F word here*?! Help!

Edited by VaporZ
Link to comment
  • Moderators

1

amount = tonumber(amount)
if amount then
  -- loop here
else
  -- inform the user that he has to fill in the amount
end

 

2

local size = table.size(playersT)

There is no table.size, only table.getn or #.
The source of following error Attempt to do arithmetic on a nil value, that occurs on line 18: local i = size + 1

arithmetic = mathematics: + - / *

 

local size = table.getn(playersT)

local size = #playersT

 

 

 

 

Edited by IIYAMA
Link to comment
6 minutes ago, IIYAMA said:

1


amount = tonumber(amount)
if amount then
  -- loop here
else
  -- inform the user that he has to fill in the amount
end

 

2

local size = table.size(playersT)

There is no table.size, only table.getn or #.
The source of following error Attempt to do arithmetic on a nil value, that occurs on line 18: local i = size + 1

arithmetic = mathematics: + - / *

 


local size = table.getn(playersT)

local size = #playersT

 

 

 

 

I'll try that tomorrow bro

Link to comment
11 hours ago, IIYAMA said:

1


amount = tonumber(amount)
if amount then
  -- loop here
else
  -- inform the user that he has to fill in the amount
end

 

2

local size = table.size(playersT)

There is no table.size, only table.getn or #.
The source of following error Attempt to do arithmetic on a nil value, that occurs on line 18: local i = size + 1

arithmetic = mathematics: + - / *

 


local size = table.getn(playersT)

local size = #playersT

 

 

 

 

Nah bro, I have a special function for table.size(theTable), but it says that it tries to preform arithmetic on a nil value on line 13, I don't know why bro.

On line 12*

12 hours ago, IIYAMA said:

1


amount = tonumber(amount)
if amount then
  -- loop here
else
  -- inform the user that he has to fill in the amount
end

 

2

local size = table.size(playersT)

There is no table.size, only table.getn or #.
The source of following error Attempt to do arithmetic on a nil value, that occurs on line 18: local i = size + 1

arithmetic = mathematics: + - / *

 


local size = table.getn(playersT)

local size = #playersT

 

 

 

 

You know what's funny? That the table.find(table, "word") isn't working the whole time! But I tought that it will work, 'cause I have a special function for that!

Anyways, I'm trying now to figure out to make depositing money to bank working

 

Gimme time please

'K! Finally! It started working

But the point is, that I need to test another way to deposit money to bank.

This way depends on, if you don't have a bank account yet!

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