question

Patrick Cloutier avatar image
0 Likes"
Patrick Cloutier asked Joshua S answered

How to sum a bunch of token label values

I have 50 labels on my tokens. These are ingredient quantities.

The label names are ing1,ing2,ing3,,,,,ing50.

I'm tying to calculate the sum of all label values this way but its not working.

int total = 0;

for (int i = 1; i <= 50; i++) {
    string tok = "ing"+tostring(i);
    total=total+token.tok;
}
return total;

Am I close?

FlexSim 20.2.3
labelsflexsim 20.2.3
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Joshua S avatar image
1 Like"
Joshua S answered

Use this instead

int total = 0;
for (int i = 1; i <= 50; i++) {
    string tok = "ing" + string.fromNum(i);
    total += token.labels[tok].value;
}
return total;
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.