Page 1 of 1
Quick Question Regarding Coding
Posted:
Thu Jun 27, 2013 10:53 pm
by SteelSaurus
Just a quick question regarding ActionScript.
I'm trying to get the {statement} from an if (condition) to display text, i.e.;
if (Winner > 1) {Result = "Champion is greater than one!"}
This works just fine. I'm wondering can I add a variable into the quote, so that;
Winner = 2 and Champion = "Victoria", then {Result = "Victoria is greater than one!"} or if champion = "Ivana" {Result = "Ivana is greater than one!"}
I'd like the 'Champion' bit to change depending on whoever the winner is, while the rest of the statement 'is greater than one', remains the same.
Any suggestions?
[[I'm learning coding!!! I'm doing well!!!]
Re: Quick Question Regarding Coding
Posted:
Fri Jun 28, 2013 12:34 pm
by KaTsuO_O
Result = Champion + " is greater than one!"
If you want it somewhere in the middle, then you can do, Result = "The champion is, " + Champion + "!"
Re: Quick Question Regarding Coding
Posted:
Fri Jun 28, 2013 2:25 pm
by SteelSaurus
I'm was aiming for the second. I take it that the plus signs (+)'s are required?
(I'm still cringing at that line 'is greater than one'...)
Re: Quick Question Regarding Coding
Posted:
Fri Jun 28, 2013 3:33 pm
by KaTsuO_O
Yeah, it won't work without them.
Re: Quick Question Regarding Coding
Posted:
Sat Jun 29, 2013 10:09 am
by BlueLight
SteelSaurus Wrote:- Code: Select All Code
if (Winner > 1) {Result = "Champion is greater than one!"}
This works just fine. I'm wondering can I add a variable into the quote, so that;
Winner = 2 and Champion = "Victoria", then {Result = "Victoria is greater than one!"} or if champion = "Ivana" {Result = "Ivana is greater than one!"}
I'd like the 'Champion' bit to change depending on whoever the winner is, while the rest of the statement 'is greater than one', remains the same.
Any suggestions?
[[I'm learning coding!!! I'm doing well!!!]
In java this is how you could do it.
- Code: Select All Code
if (winner == 2 && Champion.equals("Victoria")){Result = "Victoria is greater than one!"}
else if (Winner > 1) {Result = "Champion is greater than one!"}
or you could just do
- Code: Select All Code
Result = Champion;
if (winner == 2 && Champion.equalsIgnoreCase("Victoria")){Result = "Victoria";}
else if (Winner > 1) {Result = Result +" is greater than one!";}
Likely, the equalsIgnoreCase method is something different flash (not even sure if i did it right here.). Basically you want to find a method in the String class that takes a String and returns a boolean based on if the text in the string is the same. If you were to say String1 == String2, then you would get a false everytime except for the 1 exception(unless flash is different). This is literally because of objects are different. If you said String1 = string2 then you could compare it, you would get a true result.
Re: Quick Question Regarding Coding
Posted:
Sat Jun 29, 2013 7:37 pm
by SteelSaurus
Thank you again, I got this part working.