# Load Individual Characters from a String Into an Array?

Just started using Construct 2? Post your questions here

### » Sun Sep 20, 2015 7:09 pm

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.

EX:

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.

[b]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!
B
4
Posts: 2
Reputation: 224

### » Mon Sep 21, 2015 12:49 am

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

LettersArray.capx
B
67
S
24
G
7
Posts: 1,519
Reputation: 11,084

### » Mon Sep 21, 2015 7:05 am

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!
B
4
Posts: 2
Reputation: 224

Return to Beginner's Questions

### Who is online

Users browsing this forum: No registered users and 2 guests