Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why can't I perform arithmetic on an integer? [closed]

Asked by 9 years ago

Output:

18:49:43.694 - Workspace.TModule:4: attempt to perform arithmetic on local 'a' (a table value)
18:49:43.694 - Stack Begin
18:49:43.694 - Script 'Workspace.TModule', Line 4 - method GeneratePlate

Source Code:

--continued, but this is the only part that errors.
function tm.GeneratePlate(a,b,c,type,x,y,z)
    if a%2~=0 then
        a=a-1
    end 
--continued, but this is the only part that errors.

Running Code:

tm:GeneratePlate(10,math.random(50,200),10,math.random(0,17),math.random(-200,200),0,math.random(-200,200))

I don't understand what's wrong with anything. All of this should work, I looked over it again and again.

Locked by adark, 2eggnog, and TofuBytes

This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.

Why was this question closed?

1 answer

Log in to vote
5
Answered by
BlueTaslem 18071 Moderation Voter Administrator Community Moderator Super Administrator
9 years ago

As it says, it believes a is a "table value," rather than an integer.

It is correct! Be careful about using methods (:).


Use tm.GeneratePlate instead of tm:GeneratePlate.

Methods are sugar. They automatically add the object you are calling them on as the first argument:

tm:GeneratePlate( ... ) de-sugars to tm.GeneratePlate(tm, ... )which makes the first argument (a) actually tm -- "a table value", rather than the first argument you typed.

0
Wow, you're on a roll! Thanks! ChipioIndustries 454 — 9y
Ad