Quick Question Regarding Coding

A place for tutorials on how to get the most out of Flash

Quick Question Regarding Coding

Postby SteelSaurus » Thu Jun 27, 2013 10:53 pm

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!!!]
I'll get right on it! Eventually...
SteelSaurus
 
Joined: Sun Jun 20, 2010 3:49 am

Re: Quick Question Regarding Coding

Postby KaTsuO_O » Fri Jun 28, 2013 12:34 pm

Result = Champion + " is greater than one!"

If you want it somewhere in the middle, then you can do, Result = "The champion is, " + Champion + "!"
Don't create a porn game if you're only interested in porn.
Wise words regarding criticism http://www.youtube.com/watch?v=-98ZFl1sKt4
User avatar
KaTsuO_O
 
Joined: Tue Nov 02, 2010 6:03 pm

Re: Quick Question Regarding Coding

Postby SteelSaurus » Fri Jun 28, 2013 2:25 pm

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'...)
I'll get right on it! Eventually...
SteelSaurus
 
Joined: Sun Jun 20, 2010 3:49 am

Re: Quick Question Regarding Coding

Postby KaTsuO_O » Fri Jun 28, 2013 3:33 pm

Yeah, it won't work without them.
Don't create a porn game if you're only interested in porn.
Wise words regarding criticism http://www.youtube.com/watch?v=-98ZFl1sKt4
User avatar
KaTsuO_O
 
Joined: Tue Nov 02, 2010 6:03 pm

Re: Quick Question Regarding Coding

Postby BlueLight » Sat Jun 29, 2013 10:09 am

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.
User avatar
BlueLight
Gangs n' Whores Developer
 
Joined: Sat Jun 04, 2011 8:23 am

Re: Quick Question Regarding Coding

Postby SteelSaurus » Sat Jun 29, 2013 7:37 pm

Thank you again, I got this part working.
I'll get right on it! Eventually...
SteelSaurus
 
Joined: Sun Jun 20, 2010 3:49 am


Return to Tutorials



Who is online

Users browsing this forum: No registered users