Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Using two Arrays

New Here ,
Feb 03, 2013 Feb 03, 2013

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);

TOPICS
ActionScript
552
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 03, 2013 Feb 03, 2013

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

     clueTextField.text = clues[number];

Translate
LEGEND ,
Feb 03, 2013 Feb 03, 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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2013 Feb 03, 2013

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2013 Feb 03, 2013

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

     clueTextField.text = clues[number];

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 03, 2013 Feb 03, 2013

My God, you are smart. Thank you yet again I'm very grateful!!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 03, 2013 Feb 03, 2013
LATEST

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines