Load Individual Characters from a String Into an Array?

0 favourites
  • 4 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • I have searched many permutations of the above title on the forum,s but have not found something that was, at least obviously, the answer to my question. Sorry inadvance if this was answered already and i was too dense to understand it, initially!

    TL;DR: How do I load each individual character from a word/string into a separate element of a 1D array. Ex.: "bell" is loaded into a 1D array like: {b,e,l,l}

    My situation:

    Players tare tasked with guessing a word or words within a given category, and when a player enters their guess, the game will return out how many letters are in common between the word they guessed and the "target word".

    The way I've theorized how I can have my game do this comparison is to load individual letters of the "target" word into an array. Then, when the player submits a "guess" word, to compare it to the "target" word, increment a global or local variable whenever it finds a common letter between the two words, and then return the local/global variable for the player to see.


    1) The "target" word to guess is: "bell"

    2) The array stores the "target" word as : {b,e,l,l}

    3) Player submits "love" as a guess

    4) "love" i loaded into another array like: {l,o,v,e}

    5) Then, each letter in "love" is compared against each letter in "bell".

    6) Since these two words have 2 letters in common (l and e), then the game will return 2 and display it to the player.

    To reiterate, I'm having trouble with steps 2, and 4.[/b]

    Maybe I'm going about this inefficiently, so if you think of an even better way of implementing this central function of comparing the characters of one word to another, please let me know!

  • see... if this helps you.....


  • WOW Korbaach! That is just the kind of functionality i was looking for! Also, i appreciate the extra effort you put into basically making a Minimum Viable Product version of the game i described! I will certainly utilize some of your ideas, and give you credit when i finish

    Thanks again!

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Hello!

    I had this morning the same trouble, and I discovered that if you use this expression:

    Set value at yourArray(loopindex,0,0)to tokenat(yourText.text,loopindex,"") (please, notice the blank quote at the end)

    It will write in your array the individuals characters of any string, one by one.

    The loopindex should be the len of yourText-1, and the array should have to be enough to store the individuals characters, this is, it has to have the same Height, width or Depth than the len of yourText.

    And done!

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