how do you make an if then code
In which language? The method varies dependingā¦
my code is in python
Then, it would be something like:
if enemy:
hero.attack(enemy)
else:
# Do something else...or, delete the else clause, to do nothing
If/Then is a statement predominant in Basic. In Python, the āthenā is impliedā¦such as:
if there is an enemy:
then do this
thanks for the help, once again
Thanks for asking! (20 lines of code on the wallā¦)
Oh, btw, notice the there is no āend ifā required either.
how would i do it if i want something to happen when I beat my goal
if thisVariable > thatVariable: # this test to see if the goal has been exceeded; thatVariable = goal
# here's the code to perform once thisVariable is greater
elif thisVariable < thatVariable:
# do something else instead to increase thisVariable
Of course, this snippet is assumed to be placed within a loop, where the variables are appropriately refreshed.
so would it be
if āguardianā:
x = 35
y = 18
else:
trap.direction = āhorizontalā
Donāt forget to format you code
Possiblyā¦I read that as:
if there's a guardian:
x = 35
y = 18
else:
trap fires flat
That could be viable code.
ok ill remember next time
i tried my code and the if-else doesnāt work
Okā¦how about moving this to the Level Help. Post your code and the issue you are seeing (error pics would be good too, if any). Be sure to include the level name too, please.
This will offer the issue to the rest of the forum, as an actual issue.
so do i ask how to do the if-else code
In the example you just gave you did show the else clause. Just re-post as a Level Help, stating the issue and showing your code/picsā¦weāll get you going