How do I pull a word from an array (advanced)

Get help using Construct 2

Post » Tue Jan 12, 2016 1:26 am

Ok ! I know how to add words to an array and know how to get them back out.

My question is how do I pull each letter out and create a new array for each letter?

For first letter = C
set first letter text to C
For second letter = A
set second letter text to A
For third letter = R
Set third letter text to R

on Keypress if C set first text to visible
on Keypress if A set second text to visible
on Keypress if R set third text to visible

Trying to make pre-k learning games where display Image and type word.
if other keypressed play sound sorry try again.

any help is welcomed. Thanks in advanced. Jeremy C.
B
29
S
13
G
10
Posts: 355
Reputation: 8,327

Post » Tue Jan 12, 2016 9:16 pm

charAt() is what you are looking for:
http://www.w3schools.com/jsref/jsref_charat.asp
charat-in-a-string-with-construct-2_t81972
in C2 it is used in mid()

like mid("HELLO", 4,1) -> O
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Wed Jan 13, 2016 6:58 am

Thanks for the comment. I will have to play around with it. As the link has a link to the manual which gives descriptions of text commands and as I know not what they do or how to implement them it will be a learning curve for me to over come.

If I understand it right I will need to use tokenat(src, index, separator) to get word.
compare two variables word = answer then get random word

set text invisible
set text mid(text, index, count) 0
set global txt1 = mid(text, index, count) 0
set text invisible
set text mid(text, index, count) 1
set global txt2 = mid(text, index, count) 1
set text invisible
set text mid(text, index, count) 2
set global txt3 = mid(text, index, count) 2

on keypressed C compare global txt 1, compare global txt2, compare global txt3

if global txt = C then set Text visible
else play sorry try again.

I am sure I will have to play around with it so don't go by the code above as truth just my understanding of how it should work. from a newbies view on coding.

Thanks again for pointing me in the right direction. Jeremy C.
B
29
S
13
G
10
Posts: 355
Reputation: 8,327

Post » Wed Jan 13, 2016 9:35 am

Ok! here is what I have come up with so far.
https://www.scirra.com/arcade/puzzle-ga ... ing-b-4713

Not quite what I am looking for but it is a good start.

Thanks again for the comments. Jeremy C.
B
29
S
13
G
10
Posts: 355
Reputation: 8,327

Post » Fri Jan 15, 2016 1:03 am

Yea, everything has a learning curve, just keep pressing. We are here to help you over stumps.

Remember that indices (in arrays) start @ 0.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857

Post » Fri Jan 15, 2016 4:52 pm

gumshoe2029 wrote:Yea, everything has a learning curve, just keep pressing. We are here to help you over stumps.

Remember that indices (in arrays) start @ 0.


Yes there is a learning curve once you start building games that are not just drag and drop designs.
I try and learn new tricks everyday and have started making how to videos for construct 2.

I have really enjoyed all the advice and the tutorials that I have found.
B
29
S
13
G
10
Posts: 355
Reputation: 8,327

Post » Fri Jan 15, 2016 6:13 pm

I was wondering, are you able to use an array to randomly choose a picture, so that they aren't always in the same sequence?
B
4
Posts: 6
Reputation: 214

Post » Fri Jan 15, 2016 10:14 pm

COcatdog wrote:I was wondering, are you able to use an array to randomly choose a picture, so that they aren't always in the same sequence?


I got a snippet of code I found in this https://www.scirra.com/tutorials/685/ma ... ne-concept ( .capx) that loads images from an xml file with matching Description.Text.

If description.text = word.text then I should be able to pull letter.text.

So now I need to understand how to pull word.text = letter.text(0)&letter.text(1)&letter.text(2).

then if letter.text = word.text get random text.field
Last edited by Carbincopy on Fri Jan 15, 2016 10:23 pm, edited 1 time in total.
B
29
S
13
G
10
Posts: 355
Reputation: 8,327

Post » Fri Jan 15, 2016 10:17 pm

because I understand lettertext1 / set text to letter.text(0)
B
29
S
13
G
10
Posts: 355
Reputation: 8,327

Post » Sat Jan 16, 2016 6:14 pm

COcatdog wrote:I was wondering, are you able to use an array to randomly choose a picture, so that they aren't always in the same sequence?


Yea, you should be able to do that. Images on HTML5 websites are just URLs which you can build dynamically on the fly, so you could have an array with image names, then just randomly select from the array to build the URL, like:

Load image from URL: protocol & serverDomain & imageDirectory & ImageArray.At(random(ImageArray.Width)-1) and have it load a random image from your array.
https://www.ravenheart.ca/home
I don't check the forums much anymore, but I will receive an email for PMs.

"Someone once told me I bite off more than I can chew...

I told them I would rather choke on greatness than nibble on mediocrity."
B
23
S
6
G
1
Posts: 1,419
Reputation: 4,857


Return to How do I....?

Who is online

Users browsing this forum: Cubeeo and 27 guests