dcsimg
A Flash Developer Resource Site

Results 1 to 9 of 9

Thread: [HELP] Selecting and storing a defined letter on keypress

  1. #1
    Junior Member
    Join Date
    Mar 2004
    Posts
    16

    [HELP] Selecting and storing a defined letter on keypress

    Hey,

    I've followed tonypa's tile based game tutorial up until where I have just the walls with a dude moving around inside.

    I would like to know how to define an area of the 'maze' so that when the character is in that area, if they press a key, a pre-defined letter attached to that area is stored in a text box at the bottom of the game.

    It's kind of like a wordsearch, so each defined area must be able to have a different letter attached to it.

    The user would guide the character around, to a certain area, press a key to store that area's letter, move to their next chosen area, press a key to store that area's letter along with the previous letter...etc...etc...

    Hope you understand what I mean and thanks for any help


    PS. Don't know if this makes any difference to this part of the coding, but once the letters have been stored in the text box, I would like to be able to click on a submit button and check the series of letters from the text box against a list of words stored somewhere. Then if they match any of the listed words they'll be shown a message like "well done". I'm really not so good at explaining...
    Last edited by cm_assassin; 03-07-2006 at 06:44 AM.

  2. #2
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918
    maybe you could make some invisible movie clips that check if you're hitting them and pressing the key to add the desired letter. Something like this:
    code:
     onClipEvent (load) {
    _visible = false;
    myKey = 32; //in this case it is spacebar, but you can change it
    letterToStore = "A";
    }
    onClipEvent (enterFrame) {
    if (this.hitTest(_root.player) && Key.isDown(myKey)) {
    this.pressingKey ++;
    } else {
    this.pressingKey = 0;
    }
    //this is for the letter to be added only once
    if (this.pressingKey == 1) {
    _root.storedLetters.text += this.letterToStore;
    }
    }


    Hope it helps
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

  3. #3
    Junior Member
    Join Date
    Mar 2004
    Posts
    16
    Thanks for the help.

    I'm pretty new to Flash in this way, so let me get this straight.

    1. I create an invisible movie clip and place it where I want on my game, and create the textbox (in your example storedLetters.text?).

    2. Would I put this code on each of the invisible movie clips, and change the 'letterToStore' to suit?

    3. About the last bit of your code, does that mean that if a user presses the key 74 times on the same area of the game, it will only be added once to the text box?

    Also, where can I find the number of each key? You put 34 as spacebar, so I'm guessing each key has a different number. Would be a handy thing to know

    Thanks so so much for this help!

  4. #4
    President PhobiK's Avatar
    Join Date
    Jan 2005
    Location
    Guatemala
    Posts
    918
    You're welcome

    1. Yes, make movie clips and place them as the areas you mentioned, they are made invisible by the "_visible = false;" line. The textbox should have the instance name (in the properties window) "storedLetters" in the example, you can change it as you want. The ".text" part is refering to the text that object has.

    2. Yeah, just as you said.

    3. Nope, it means that as the code runs once each frame, if that "if" statement weren't there it would add a letter each frame as long as you have the key pressed, this way it only adds the letter once when you press the key, but if you press it more times it would add it again. If you'd like to make it as you said, please tell me.

    Yes, every key has a number. You can know it through "Key.getCode()", but here's a file that could be useful for you to know the key's codes.

    Hope it helps.
    Attached Files Attached Files
    This is MC. His _parents sent him to stop() by the super market to buy some _root beer if he wanted to gotoAndPlay() with his friends at the park later.

    This is my Blog!... The gaming Process
    Please check out my site: Giddel Creations

  5. #5
    Junior Member
    Join Date
    Mar 2004
    Posts
    16
    Thanks for the continued help and that file.. I'll have a look at it tomorrow, it's late here

    I understand it all now thanks, and yes I would like to make it so that the user can only add the letter to the textbox once if you could please.

    Also, on keypress, could I also make that invisible movie clip visible?
    Reason for this is I have a maze made out of letters which the character is guided through, and when they think they've found a letter they want.. they place the guy on it and press a key so it's added to the text box. I'd like to make it so that they don't go off somewhere else and return to the same letter and try to add it again and again thinking they've not done it before. If I could make the movie clip visible again they'd then see some indication that they've been there before...so won't try to add it again.

    Hope I'm clear. Thanks

  6. #6
    Junior Member
    Join Date
    Mar 2004
    Posts
    16
    I've just come to realise that I'm unable to create the invisible movie clips as my map is created using a two dimensional array with '1' as a non-walkable square and '0' as a walkable square, etc.

    So where could I put those invisible movie clips? Or how could I re-design the game to work differently?

    Thanks for any help!

  7. #7
    Junior Member
    Join Date
    Mar 2004
    Posts
    16
    Sorry to keep on about this, but I desperately need help. Anyone?

    Thanks.

  8. #8
    Senior Member Ray Beez's Avatar
    Join Date
    Jun 2000
    Posts
    2,796
    You're using 1 and 0 so that you can just quickly check "true/false"?
    You could start using more numbers... 2 ... 3....

    I'd also store the letters collected in an array. Every time you find one, you use myarray.push() to add a letter.

  9. #9
    Junior Member
    Join Date
    Mar 2004
    Posts
    16
    Thanks for the reply.

    As I'm a newb...I wouldn't know where to start with that advice, lol.

    Basically, I've followed TonyPa's tile based game tutorial up until the 'scrolling' section. So I have a map which a character can move around with the arrow keys, and the map scrolls with the character. I'd like to specify areas of the map that when the character is placed on, the user can press a key and store a letter that it specific to that area of the map (if possible).

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center