Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

A question regarding the "elif" snippet(?)


Alright, this is my first dive in the forum, so go easy on me please, also i’m using python.

So i have been playing for a while; breezing through the game and finish 40 levels in a few hours, but so far; the game teaches me so much advance coding; BUT, it never taught how to use the “elif” thing (dunno how to classify it), so my question is:

  1. In under what circumstances should i use it for maximum efficiency?
  2. How on Earth do you even suppose use it?
  3. (For the devs) why didn’t you guys made a level or two; dedicated for this “elif” thing? It can’t be THAT hard; to explain the uses of this “elif” thing; to the players, heck if i know how to use it already, i wouldn’t even be asking these 3 questions right now :confused:

(?) = i think that’s what you suppose to call it, but i dunno, i have only 40-50 hours of programming experience to know those complex coding name.

So… uh… thanks for reading beforehand i guess :3


most people would know elif, but here is what it is.
Not trying to offend you, but most people know it because of prior knowledge.
elif is basically a nested if inside and else.

if flag:
    moveXY(flag.pos.x, flag.pos.y)
elif item:
    moveXY(item.pos.x, item.pos.y)

is equivalent to:

if flag:
    moveXY(flag.pos.x, flag.pos.y)
    if item:
        moveXY(item.pos.x, item.pos.y)

So it is basically a compressed version of an if nested inside an else. To save space I guess.


So it’s just a shortcut?
But in the if/else section in-game; it says:

elif enemy.type is “thrower”:

i tried it myself, but i replace “thrower” with “ogre”, he didn’t do what i want him to do; so i want to know how am i suppose to tell my character that i want him to “target an ogre then bash him with a shield, but if the shield is still in cd, then use the shield while the same enemy type is still around”

Unless the game doesn’t have something like that, and i’m using the “elif” thing wrong… :c


It’s munchkin i think.


what does that mean?


The type is munchkin.


Are you sure? It says it’s an “Ogre” beside it’s name


click on the type of ogre you want to target, and it will tell you. NOT the name, the type.
(Ogre isn’t a name anyway, I think)


Nah, it’s not a name, it says the same thing among other “Ogre” with different names.
Btw how do i even know the type of the enemy i’m clicking?


You mean the big ogres, or the tiny ones.
you see the name, then after that it will say it’s type, for example:


I mean the biggest one (with full body armor, huge size and HP count)


Erm… takes a look at screen


Yeah they’re called ogre. can you post your code, and for a certain level?



Well, it’s for Backwwods Treasure
And here’s the code i’m using:

enemy = self.findNearestEnemy
elif enemy.type is “ogre”:
if self.isReady(“bash”):

and that’s it, he won’t bash’em :frowning:


what exactly are you else-ing to?



Yeah… this is where my zero knowledge of using elif got the best of me…
Also, i don’t know what you mean.


i mean elif means else if, so where is the if before the else?


Also, surround your code with triple backticks like this:


by pressing the little thing above tab 3 times = triple backticks.
surround it with them.


Dude i don’t get it :frowning:
can you just give me a line of code where "my character use bash on a specific enemy type."
the Programmaticon II told me about the method, which i think is wrong.


:tired_face: I mean that for an else, you need an if before it.