Skip to main content
Known Participant
February 3, 2013
Answered

Using two Arrays

  • February 3, 2013
  • 1 reply
  • 604 views

As part of my Hangman game I want to have two Arrays, one holding the wordlist, and one holding the clues. What I intend to do, is randomly generate a word along with the clue to that word. I've got the word generator working correctly but I'm not sure how I can make it choose a clue from a seperate array. This is what I have so far to make the Array of words work:

var words: Array = ["LONDON", "CYPRUS", "CHINA"];

This is my Array of the words

number = (Math.floor(Math.random()* 3));

inProgress = words[number];

wordLength = inProgress.length;


This is what I use to randomly Generate the word. Note: number is a number variable I created and inProgress is a String variable I created.

I would like to know how I'm able to make it randomly generate the clue along with this, using the Array:

var clues: Array = ["Capital of England", "Small Island", "Highest population"];

If it makes it easier to see the whole code leading up to this I'll paste it below for you to see. Thanks!

var words: Array = ["LONDON", "CYPRUS", "CHINA"];

var number:Number;

var inProgress: String = new String;

var wordLength:Number;

var myDisplay: Array = new Array();

var displayOut: String = new String;

var rightCount: Number = 0;

var used: String = new String;

var guess: String = new String;

var guessLetter: String = new String;

var correctGuess: Boolean = false;

number = (Math.floor(Math.random()* 3));

inProgress = words[number];

currentClue = clues[number];

wordLength = inProgress.length;

for (var i = 0; i <wordLength; i ++)

{

    myDisplay = "*";

    displayOut += " " + myDisplay

}

var answerText:TextField = new TextField();

var myFormat:TextFormat  = new TextFormat();

myFormat.font = "Segoe UI Symbol";

myFormat.color = 0X00FF00;

myFormat.size = 23;

addChild(answerText);

this.answerText.x = 375;

this.answerText.y = 40;

this.answerText.width =250;

this.answerText.text = displayOut;

answerText.setTextFormat(myFormat);

This topic has been closed for replies.
Correct answer Ned Murphy

Use a textfield and assign the clue as the text property of it.

     clueTextField.text = clues[number];

1 reply

Ned Murphy
Legend
February 3, 2013

If you order the two arrays the same then choosing the word should be no different for the clue.  Whatever random number you use for the word would be the same value you use for the clue.

Syphon25Author
Known Participant
February 3, 2013

I see, but how do I display the clue on the screen? Do I use the addChild command?

Ned Murphy
Ned MurphyCorrect answer
Legend
February 3, 2013

Use a textfield and assign the clue as the text property of it.

     clueTextField.text = clues[number];