Function that switch values in a table
Posted: Wed Dec 30, 2020 10:42 pm
Hello again,
I'm continuing my beginner attemps. I'm trying to write a function that switch values in a table.
I wrote the following funcition: it works if I enter in it directly the variables, but it doesn't if i try to pass the variables as parameters.
Can somebody help me where i'm wrong?
Thank you
I'm continuing my beginner attemps. I'm trying to write a function that switch values in a table.
I wrote the following funcition: it works if I enter in it directly the variables, but it doesn't if i try to pass the variables as parameters.
Can somebody help me where i'm wrong?
Thank you
Code: Select all
test = {"normal", "text", "imae"}
testselected = 1
function love.draw()
love.graphics.print(test[testselected])
end
function love.mousepressed( x, y, button, istouch, presses )
if button==1 then
test = switchTableParameter(test, testselected)
end
end
function switchTableParameter(param, selectedparameter)
for i = 1, #param do
selectedparameter = selectedparameter + 1
if selectedparameter > #param then
selectedparameter = 1
end
return param
end
end