compare tokens

0 favourites
  • 3 posts
  • 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.

    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.

  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Worked great, you sir are a gentleman.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)