Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 07-08-2012, 11:58 PM   #1
KhaosPath
Registered User
 
Join Date: Sep 2011
Posts: 14
Default Trouble with conditional

I was writing some code to practise. In a game I'm making I tried to use the conditional but the game only responds to the first "if" of the conditional?
Any thoughts?

ActionScript Code:
public function playGame():void         {             output.text=("Is it ")+computerGuess;             playerTurn();         }         public function playerTurn():void         {             if(input.text=="yes")             {                 output.text=("Oh Yeah!");                }             if(input.text=="no")             {                 output.text==("Let me try again!");             }

What happens is that the game only responds if I type "yes". When I type "no" it doesn't react.

Thanks in advance.
KhaosPath is offline   Reply With Quote
Old 07-09-2012, 12:10 AM   #2
FusionFactor
Senior Member
 
FusionFactor's Avatar
 
Join Date: Jun 2011
Posts: 183
Default

Try using "else if" for the second statement.

ActionScript Code:
if(input.text=="yes") {     output.text = "Oh Yeah!";    } else if(input.text=="no") {     output.text = "Let me try again!"; }
FusionFactor is offline   Reply With Quote
Old 07-09-2012, 03:25 AM   #3
henke37
Senior Member
 
henke37's Avatar
 
Join Date: Mar 2009
Location: Sweden
Posts: 10,835
Send a message via Skype™ to henke37
Default

You have mixed up assignment and comparison, in the unusual direction.
__________________
Signature: I wrote a pair of articles about the timeline.
henke37 is offline   Reply With Quote
Old 07-09-2012, 10:31 AM   #4
KhaosPath
Registered User
 
Join Date: Sep 2011
Posts: 14
Default

Thanks for the replies.
I had already tried the else if. It didn't work, so I began trying everything (else, else if, if). But neither of them worked.
I tried to change theier order, apperently only the first one runs.

Have you any ideas of what I must do?
KhaosPath is offline   Reply With Quote
Old 07-09-2012, 01:51 PM   #5
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,398
Default

ActionScript Code:
import flash.text.TextField; var input:TextField = new TextField(); input.text = "yes"; addChild(input); var output:TextField = new TextField(); output.y = input.y + input.height; addChild(output); playGame(); function playGame():void {     playerTurn(); } function playerTurn():void {     if (input.text == "yes")     {         output.text = "Oh Yeah!";     }     if (input.text == "no")     {         output.text = "Let me try again!";     } }
[afz]snickelfitz is offline   Reply With Quote
Old 07-09-2012, 04:02 PM   #6
KhaosPath
Registered User
 
Join Date: Sep 2011
Posts: 14
Default

Quote:
Originally Posted by [afz]snickelfitz View Post
ActionScript Code:
import flash.text.TextField; var input:TextField = new TextField(); input.text = "yes"; addChild(input); var output:TextField = new TextField(); output.y = input.y + input.height; addChild(output); playGame(); function playGame():void {     playerTurn(); } function playerTurn():void {     if (input.text == "yes")     {         output.text = "Oh Yeah!";     }     if (input.text == "no")     {         output.text = "Let me try again!";     } }
I tried what you suggested, but it still isn't working.
I'm running out of ideas.
KhaosPath is offline   Reply With Quote
Old 07-09-2012, 04:33 PM   #7
[afz]snickelfitz
Senior Member
 
[afz]snickelfitz's Avatar
 
Join Date: Dec 2011
Location: Tucson, AZ
Posts: 2,398
Default

The conditional logic in the code I posted works fine and is observably correct.
You probably have typos or sytax issues in other areas of the application, similar to the "==" mistake in your original posted code.
[afz]snickelfitz is offline   Reply With Quote
Old 07-09-2012, 04:39 PM   #8
FlexFlashApps
developer
 
Join Date: Jul 2011
Posts: 183
Default

ActionScript Code:
public function playGame():void {     playerTurn();     output.text=("Is it ")+computerGuess; }


What is your computerGuess?



FFA
FlexFlashApps is offline   Reply With Quote
Old 07-11-2012, 08:42 PM   #9
KhaosPath
Registered User
 
Join Date: Sep 2011
Posts: 14
Default

Thank you all.
I enventually decided to redo it from scratch and apperently the problem is gone.
Thank for the help any way.

P.S:computerGuess is just a varibale which stores a random number.
KhaosPath is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 08:36 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.