For some reason i can do every operation except for diving theese 2 variables. I've tried every aleternative to round them and still nothing changes. The code first sum's up an array with numbers it got from a for loop. Heres the code:
{% set number1 = list_number|sum|round(1) %} {% set number = numbers|sum|multiply(10)|round(1) %}
{{ number / number1 }}
and this is the error it comes up with when i try to publish:
@AKoprivec If you add {{ number }} and {{ number1 }} at the very end of the code what do the variables return (note that you can't divide by zero, so if they're returning the default value it's going to error out)?
If this answer solved your question, please mark it as the solution.
They both return a number, all operations besides / and // work completly fine on both numbers, and it doesn't show any red alerts saying it can't devide with 0 like it does if i do {{number}}/0 instead it just gives an orange alert on that line.
{% set list_variable = request_contact.list_memberships %}
{% set numbers = [] %}
{% set list_number = [] %}
{% for i in module.questions %}
{% for list in i.lists %}
{% if list.list_id in list_variable %}
{% do numbers.append(list.list_value) %}
{% endif %}
{% endfor %}
{% do list_number.append(1) %}
{% endfor %}
{% set number1 = list_number|sum|round(0) %}
{% set number = numbers|sum|multiply(10)|round(0) %}
The module gets all of the contacts lists and checks which of them are the same as the ones input into fields and then assigns them the corresponding value. The top part of the script should work fine, as the end result is 2 numbers. Every single operation between them works just fine except for / and //. And yes all the modules have a set default number of 0 (both list_id and list_value).
what are list_number and numbers? Are they set before your calculation?
You have to define them somehow. For example like this:
{% set list_number = 2 %}
{% set numbers = 5 %}
{% set number1 = list_number|sum|round(1) %}
{% set number = numbers|sum|multiply(10)|round(1) %}
{{ number / number1 }}
Yes the array isnt empty, just using {{ number }} and {{ number1 }} displays both numbers (assuming as integers since other operations work ) just fine. Is there maybe any other way to run variables out of the for loop without appending the numbers to an array