AlexMiller Posted July 29, 2010 Share Posted July 29, 2010 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! Link to comment
blas95 Posted July 29, 2010 Share Posted July 29, 2010 You are defining a local variable, and then using it outside its scope. Or maybe, I misunderstood the error. Also try tonumber(itscost) Link to comment
AlexMiller Posted July 29, 2010 Author Share Posted July 29, 2010 I'm using it locally, in the same script, in the same function. Link to comment
blas95 Posted July 29, 2010 Share Posted July 29, 2010 Um, can you paste greater portion of code? Error says about arithmetic on tax2 but in this code you are performing arithmetic on itscost Link to comment
AlexMiller Posted July 29, 2010 Author Share Posted July 29, 2010 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 Link to comment
AlexMiller Posted July 29, 2010 Author Share Posted July 29, 2010 Can anyone help me out with this? Link to comment
blas95 Posted July 29, 2010 Share Posted July 29, 2010 (edited) If creates scope, and tax2 is local to this if. Remove local keyword and this will work. Tested. @down: No problem Edited July 29, 2010 by Guest Link to comment
AlexMiller Posted July 29, 2010 Author Share Posted July 29, 2010 There was the problem, thanks you now it properly works! 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