A question regarding the "elif" snippet(?)


#1

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


#2

Ah.
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)
else:
    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.


#3

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

elif enemy.type is “thrower”:
self.attack(enemy)

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


#4

It’s munchkin i think.


#5

@ARasberrypy-thon
what does that mean?


#6

The type is munchkin.


#7

@ARasberrypy-thon
Are you sure? It says it’s an “Ogre” beside it’s name


#8

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)


#9

@ARasberrypy-thon
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?


#10

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


#11

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


#12

Erm… takes a look at screen


#13

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


#14

@ARasberrypy-thon

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

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

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


#15

what exactly are you else-ing to?


#16

@ARasberrypy-thon

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


#17

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


#18

Also, surround your code with triple backticks like this:
loop:
becomes

loop:

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


#19

@ARasberrypy-thon
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.


#20

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