setVariable never worked for me either. I've tried.
Only thing that has worked for me is
___
return myFunction()
Or
return myFuntion(parameters)
But if you are just trying a simple function to update a variable, why don't you just put your resultadoqtd variables into an array instead of separate variables. The array woud look like this (and you could call it resultadoqtdArray):
["resultadoqtd1", "resultadoqtd2", "resultadoqtd3", "resultadoqtd4", "resultadoqtd5", "resultadoqtd6", "resultadoqtd7", "resultadoqtd8", "resultadoqtd9", "resultadoqtd10", "resultadoqtd11", "resultadoqtd12", "resultadoqtd13", "resultadoqtd14", "resultadoqtd15"]
You can build an array programatically using a loop and the "append" option in the set variable block.
And then your variables are now:
{{={{resultadoqtdArray}}[{{index}}]=}} or {{={{resultadoqtdArray}}.at){{index}})=}}
I prefer the first way- examples from typebot documentation here:
Variables in TypebotThen, all that you need to do is set your index based on which value in the array you want modified (assuming you are storing that in {{codigoaremover}} - which I would write as {{codigoA_Remover}} or something more obvious.
just corelate that to the index somehow so you are getting the correct value and remember arrays start at 0 so {{resultadoqtd1}} would now be
{{={{resultadoqtdArray}}[0]=}}
So you basically have to specify which product in the array you are going to change the value for and set that to your index variable. then your code block is just:
{{={{resultadoqtdArray}}[{{index}}]=}} = {{={{resultadoqtdArray}}[{{index}}]=}} - {{Quantidade a remover}}
That is all you need
Should work fine but I am curious if there is a way to make that setVariable funtion work to set typebot variables through javascript if @baptiste weighs in.