I have a code that multiplies an integer and adds another integer. but for some reason it seems not to be working.

my code:

function multiply_list_with_number(list,int,new_int)
    for l,i,ni in pairs(list,int,new_int) do
        return(l*i+ni)
    end 
end

multiply_list_with_number({0,2,4,5},2,5)

my error i get is

lua: main.lua:17: attempt to perform arithmetic on a nil value (local 'ni')
stack traceback:
	main.lua:17: in function 'multiply_list_with_number'
	main.lua:21: in main chunk
	[C]: in ?

4 comments

0

Do you want to multiply each element of the list by the second number parameter and then add the third parameter number to it? Your script does not work because pairs takes only one parameter and that is table and returns 2 values, Index and Value.

0

@imkirda can you please add code?

0

I can, however, i am not exactly sure what are you trying to achieve, that's why i asked: Do you want to multiply each element of the list by the second number parameter and then add the third parameter number to it? If so then you can try this https://pastebin.com/SACHZViR

0

Thankyou @imKirda that was what was trying to do!