How do I compare for each element in my array at x ?

0 favourites
  • 12 posts
From the Asset Store
🙌 Element Magic Hit Sound Pack comes with 805 high-quality sound effect
  • I make loops for the x row from 0 - 90

    And on each row cointains value of string that i load from file.txt using ajax and tokenat to seperate them. How do i compare each element current value is equal to my text input then do such things?

    Here my capx drive.google.com/file/d/1AeUEKYGCLedlp9wfeU8cbqoACxRvTKVj/view

  • If you want a simple true or false you can use 'array contains value' where the value is text.text. It depends what kind of data you are trying to pull from the array. Do you just want to know if it exists, or do you need to know its position?

    By the way instead of that global variable logic you can use 'loopindex' as the position in a loop, instead of l.

  • If i use array contains value, its only check the value at 0

    I want it check all of them from 0-90

    I use compare 2 values

    If array.at(0.loopindex)=text.text

    Then do such things

    But it not check the whole array value from 0-90.

    Even if i use curX.

    Would you mind to see the capx? Pls

  • How do i campare array.at(0-90, loopindex)?

    Can the code be like that? I want it check all the values

  • contains value only takes a string.

    That should work:

  • Tried that one but the text change only when i search for Adela value, if i search Jalen or Gardenia its not work. Even if i debug the Adela, Jalen, Gardenia was not even in array.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • When search Adela it change

    But when i search Gardenia it not change

  • And i change my event like this

  • It doesn't work because you have white spaces in your text file. You have to use trim to eliminate them and if your search isn't case sensitive I would also use lowercase.

    That should now work:

    + System: On start of layout

    -> Array: Set size to (0, 1, 1)

    -> AJAX: Request mproduct.txt (tag "produkt")

    + AJAX: On "produkt" completed

    ----+ System: For "" from 0 to tokencount(AJAX.LastData,";")-2

    -----> Array: Push back lowercase(trim(tokenat(AJAX.LastData,LoopIndex,";"))) on X axis

    + TextBox: On text changed

    -> Text: Set text to TextBox.Text

    + Button: On clicked

    ----+ Array: Contains value lowercase(trim(Text.Text))

    -----> Text: Set text to "found"

    Image Upload doesn't work.

  • Okay it works! But last thing is how can i ignore the uppercase or lower case in search input? Let say if i search Adela and the value is adela i can still find it?

  • in my last example, the search is case insensitive. You can write upper- or lowercase and it will find the word. If you don't want that delete the lowercase expression.

  • I put uppercase on searchtext, so whatever the the text input it will be uppercase, and at the array also i put uppercase. Problem solved !

    Tqsm man. I love construct will buy soon tq bro ! Tqsm

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