Jump to content

[HELP] Arithmetics issue


Recommended Posts

Posted

Hi there. I'm ahving some problems with my payday script. It gets the cost of the car a player has and divides it for 1000 to get the tax you have to pay for owning it. The problem is that when i try to perform this arithmetic:

local tax2 = itscost /1000

I get this error:

attempt to perform arithmetic on global 'tax2'

I have already checked if itscost is true by using some outputchatbox and printing it. It shows the car cost correctly. Thanks for helping! :D

Posted

You are defining a local variable, and then using it outside its scope.

Or maybe, I misunderstood the error. Also try

tonumber(itscost)

Posted

Um, can you paste greater portion of code?

Error says about arithmetic on tax2 but in this code you are performing arithmetic on itscost

Posted

Alright. That 2 ouputchatboxs were written to check if the variables were wroking fine.

function PayDay(plr, givepay)
 
local reincome = 200
local account = getPlayerAccount (plr)
local findcar = tonumber(getAccountData (account, "car"))
if findcar ~= 481 then
local itscost = tonumber(getAccountData (account, "carcost"))
outputChatBox("cost is " ..itscost)
outputChatBox("car is " ..findcar)
 
local tax2 = itscost/1000
else
local tax2 = "0"
end
 
local whatisgiven = reincome - tax2
 
local playerList = getElementsByType("player")
for key,val in ipairs(playersList) do
givePlayerMoney(val, whatisgiven)
 
end

Posted (edited)

If creates scope, and tax2 is local to this if. Remove local keyword and this will work. Tested.

@down: No problem :)

Edited by Guest

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