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

0 favourites
  • 10 posts
From the Asset Store
Advanced inventory mechanics for your RPG game (Array-based). Take Items, split them, pick up them, read the description
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • 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.

  • 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.

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

    Remember that indices (in arrays) start 0.

  • 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.

  • 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 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

  • because I understand lettertext1 / set text to letter.text(0)

  • 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.

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