compare tokens

Get help using Construct 2

Post » Wed Oct 19, 2016 6:45 pm

Anyone know why this code doesn't work? There's a flaw in my logic i guess but i just can't see it.

I have a bunch of instances with a string variable "myNumbers" used to hold tokens of different numbers.
One instance may look like this "1,5,6,2" and another like this "3,5", they're all different.

I have a global string "deleteNumbers" holding a group of token numbers in the same way.

I want to loop over the instances, compare their numbers with the deleteNumbers and record the numbers from "myNumbers" that don't match and put them into another string variable "newNumbers".

for example if "deleteNumbers" = "1,5,8,9"
and an instance "myNumbers"="1,3,2,9"
then the instance "newNumbers" = "3,2" the 1 and 9 are not recorded.

Here's the events, and .capx file.

Image

https://dl.dropboxusercontent.com/u/159885981/deleteNum.capx

I tried simply using "system find" expression combined with the "system replace" expression but it matches individual characters and not tokens so 1 deletes 11, or if the number was say 17 it would delete the 1 and leave 7.

Any ideas?

Thanks.
B
43
S
23
G
20
Posts: 735
Reputation: 12,027

Post » Thu Oct 20, 2016 6:38 am

You're comparing every pair of numbers and only add to new numbers that don't match.
So for example if your lists are
My=1,3,4
Del=2,4

Then all you comparisons would be:
1=2
1=4

3=2
3=4

4=2
4=4

So your readily is:
New =1,1,3,3,4

What you want is to to know is if the current number from my list is in the delete list before adding it to new. Here is one way. Hopefully the event nesting is evident.
For each my_list
--var save=1
--for each del_list
----if cur_my = cur_del
------set save to 0
--if save=1
---- add cur_my to new

Another way would be to use find() by converting the delete list from:
1,3,5
To
,1,3,5,
Then you could do this:

For each my_list
--if find(del_list, ","&cur_my&",") = -1
---- add cur_my to new
B
92
S
32
G
110
Posts: 5,295
Reputation: 71,501

Post » Thu Oct 20, 2016 3:43 pm

Worked great, you sir are a gentleman.
B
43
S
23
G
20
Posts: 735
Reputation: 12,027


Return to How do I....?

Who is online

Users browsing this forum: Armench, Jackriduk, kiki4construct and 26 guests