Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I’m new to coding, and I mostly only know variables and booleans in swift.
I’ve been trying to code a pokemon-esqe thing, and here’s what it looks like:

Var charmander = “fire”
Var squirtle = “water”
Var bulbasaur = “grass”

“Water” > “fire”

Var battle1 = squirtle > charmander (true)

(The thing is, when I try to code the grass part, it returns false. Look.)

“water” < “grass” (false)
“grass” > “water” (false)

“fire” > “grass” (false)
“grass” < “fire” (false)

I need to get grass to work for the code to work the way I want, and it’s not working like this.

What I have tried:

I’ve tried both combinations of code (E.G. fire > grass and grass < fire), and have tried retyping “grass” in the initial variable, but it still doesn’t work! I don’t know wat to do.
Posted
Comments
Richard MacCutchan 13-Aug-18 3:27am    
Look at those strings. "water" is always greater than "grass" in normal sort sequence.
Member 13946784 13-Aug-18 10:25am    
How so?
Richard MacCutchan 13-Aug-18 10:57am    
What do you mean by "how so"? They are alphabetic strings, so they will be compared alphabetically. So "grass" always comes before (is less than) "water".
Member 13946784 13-Aug-18 21:41pm    
Oh, sorry. I’m just REALLY new to coding, and had no idea. Thank you for your answer!
Richard MacCutchan 14-Aug-18 3:23am    
Spend some (a lot of) time learning the language and its rules. You cannot learn programming by posting questions in forums like this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900