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

Changing my Display...

New Here ,
Jan 28, 2013 Jan 28, 2013

OK! So, I've been developing my hangman game for quite some time now and this is basically how it works. Array of words, randomly generates one of the words, converts it into underscores and creates spaces between each underscore. What the user has to do, is enter a letter into the input text, push the guess_btn and then it will trace to see if the guessed letter is equal to the one that was randomly selected. If it is, it will convert it back into a letter and increase the rightcount. If it's not, then the movie clip will increase by one moving closer to the person dying. Sounds fairly simple. But the problem I have, is that even though it traces "True" on the correct letter, the "myDisplay" (which is the underscores) doesn't change the underscore to the guessed letter. Now I'm gonna paste a swath of code as how I think the game should function, and I'm going to highlight where the problem is in the code. Or where I think it is. All I want someone to say is "Oh, it's not changing from underscores because..." Please, please... Please, help me! I haven't got very long to make this game and I really need help! Thank you!

stop();

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

//Creates array of the words to choose from

var number:Number;

var inProgress: String = new String;

var wordLength:Number;

var myDisplay: Array = new Array();

var displayOut: String = new String;

//Store number for correct guesses

var rightCount: Number = 0;

//Stores incorrect guesses

var used: String = new String;

//Holds the correct guess'd letter

var guess: String = new String;

//Holds the users correct guess

var guessLetter: String = new String;

//Holds the status of the guess

var correctGuess: Boolean = false;

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

//Generating a random number

inProgress = words[number];

//Stores current word in the "inProgess" variable

wordLength = inProgress.length;

//Calculates legnth of the word

//For statement is used when you know how many times to loop

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

{

myDisplay = "_";

displayOut += " " + myDisplay;

}

//Creating the text in the text field for used letters

var answerText:TextField = new TextField();

var myFormat:TextFormat  = new TextFormat();

myFormat.font = "Segoe UI Symbol";

myFormat.color = 0X00FF00;

myFormat.size = 23;

//The location of the text field

addChild(answerText);

this.answerText.x = 375;

this.answerText.y = 40;

this.answerText.width =250;

this.answerText.text = displayOut;

answerText.setTextFormat(myFormat);

this.guess_btn.addEventListener(MouseEvent.CLICK, playMe);

function playMe(Event:MouseEvent):void

{

//Switches all letters to capital

guessLetter = this.letterIn_txt.text.toUpperCase();

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

{
if(inProgress.charAt(i) == guessLetter)
{

trace("true");
myDisplay=guessLetter;
correctGuess=true;
rightCount++;
}
}

}

if (correctGuess==false)

{

used+= this.letterIn_txt.text;

this.usedLetters_txt.text = used;

this.Comp.nextFrame();

}

else

correctGuess=false

displayOut = "";

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

{

displayOut += " " + myDisplay;

}

this.answerText.text= displayOut;

this.answerText.setTextFormat(myFormat)

this.letterIn_txt.text = "";

if (rightCount == wordLength)

{

removeChild(answerText)

//Takes you to Scene 2

gotoAndStop(103)

}

TOPICS
ActionScript
623
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 01, 2013 Feb 01, 2013

That changes the value in the array, but that does not change the value being displayed.

Elsewhere (see below) you write to that display (I think), but it is outside of any function that might be getting called after the new letter is added to the array, so it is only being executed oce when the file first starts running.

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

{

displayOut += " " + myDisplay;

}

this.answerText.text= displayOut;

Try putting that code inside a function and have that function called anytime yo

...
Translate
LEGEND ,
Jan 28, 2013 Jan 28, 2013

In the code you highlighted, put: trace(myDisplay);  and see what it is as you progress thru the game. 

I don't see where changing anything in the array updates anything else, which might be related to your problem.

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 ,
Jan 29, 2013 Jan 29, 2013

Very interesting! I done and under my output, along with the "True" statement, this appeared:

true

_,_,_,_,_,_

true

C,_,_,_,_,_

true

C,Y,_,_,_,_

true

C,Y,P,_,_,_

true

C,Y,P,R,_,_

true

C,Y,P,R,U,_

true

C,Y,P,R,U,S

So why isn't the underscores on screen changing?

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 ,
Jan 29, 2013 Jan 29, 2013

As I already indicated, I don't see anywhere in your code where you are chnaging anything with respect to changing the myDisplay array... though I haven't looked beyond the code you highlighted.  Where in your code do you take the newly assigned value of myDisplay and assign it to some display element?  Find why that is not haoppening and your mystery will be solved.

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 ,
Jan 29, 2013 Jan 29, 2013

I thought myDisplay=guessLetter; would change it since myDisplay is the underscores, and the guessLetter is the letter the user inputed which is correct. Did I do something wrong there or is that just incorrect?

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 01, 2013 Feb 01, 2013
LATEST

That changes the value in the array, but that does not change the value being displayed.

Elsewhere (see below) you write to that display (I think), but it is outside of any function that might be getting called after the new letter is added to the array, so it is only being executed oce when the file first starts running.

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

{

displayOut += " " + myDisplay;

}

this.answerText.text= displayOut;

Try putting that code inside a function and have that function called anytime you need to update the displayed text.

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