• Welcome to The Cave of Dragonflies forums, where the smallest bugs live alongside the strongest dragons.

    Guests are not able to post messages or even read certain areas of the forums. Now, that's boring, don't you think? Registration, on the other hand, is simple, completely free of charge, and does not require you to give out any personal information at all. As soon as you register, you can take part in some of the happy fun things at the forums such as posting messages, voting in polls, sending private messages to people and being told that this is where we drink tea and eat cod.

    Of course I'm not forcing you to do anything if you don't want to, but seriously, what have you got to lose? Five seconds of your life?

mewtini
Reaction score
3,705

Profile posts Latest activity Postings About

  • (the code isn't long, it's just in hide tags because it looks really bad in the middle of normal text. Aaand pretend indenting exists.)

    Okay about the join. So here's the line we used that wasn't working:


    enemy_fort = [fort for fort in self.forts if fort != team][0]


    You at least sort of remember that, right!

    The part in brackets is a list comprehension! A list comprehension means instead of making a list and then writing code, like:


    my_cats = []

    for cat in all_cats_ever:
    if cat.owner == me:
    my_cats.append(cat)


    You stick the code into the brackets!


    my_cats = [cat for cat in all_cats_ever if cat.owner == me]


    List comprehension syntax is a little bit confusing to learn, but it has some benefits, like: shorter (one line versus four), can be a lot easier to read once you're used to it, and also doesn't pointlessly start an empty list just to append to it. Shorter isn't the goal and you should totally use long code whenever it's easier for you to understand, but sometimes shorter is inherently easier to understand.

    Here's a sample of when a list comprehension looks like a mess, too:


    data = [(data[i-1].lower().capitalize() + ", " + data).split(", ") for i in range(0, len(data), 3)][1:]


    You can tell what the [cat for cats] thing is saying pretty easily, especially when you get used to list comprehensions! But that one up there is confusing and you have to think about it and maybe read more code for context of what's going on before you can edit it. I know what it means because I wrote it recently! (because I was having too much fun experimenting with squishing it all into a list comprehension) But if I forget later it'd take me some energy to work it out. And then once you get what it's doing it's unclear *why* it's doing it. What's the deal with only doing all that data splitting and lowering every three numbers! (that's what that for i in range does) What's so special about every third thing and second thing (I look at third number minus one, too) in the data. Why am I splitting things up! What's data[i-1]. Why do I use [1:] which throws out some arbitrary items from the finished list. Who knows. (It's because I'm parsing a text file for Pokemon attacks and the first couple of lines are a title and an empty, so those are garbage to me. And the other part is because every three lines are attack names! And the line i-1 is above the attack names and is the type like Bug. But who would know that.) Also it's harder to edit because there's a loooot of room for hard-to-notice typos in all those parentheses and brackets. Actually when I was working on that code I introduced a bunch of typos that took way longer to fix than they would have if I hadn't had all that squished into one line.

    Anyway, you don't actually need to know that stuff. What you do need to know is that we're doing this with the non-working code:


    for player in self.forts:
    if player != person_who_typed_the_attack_command:
    enemy = player


    Since there's only two forts in a game, whichever fort isn't the attacker's fort must be the enemy's fort! Except we stuck it in a list comprehension. So instead of: enemy = "Mewtini" We actually have: enemy = ["Mewtini"]

    You're trapped inside a list!!! So ["Mewtini"][0] takes the zeroeth item (and only item) out of the list so that we *do* have enemy = "Mewtini".

    But for some reason that caused a problem. So instead of that we have "".join["Mewtini"] which joins all the list items together except there's only one so we just end up with the string "Mewtini". Just. like. it should've. been. already.

    *And* we printed out the value before the join statement and it was a right value. It just didn't work before??? I'm sure there's a good explanation and we're just missing some detail but I have no idea what it is. So I gave up and left the join part! I added it in the first place just to be sure we were creating an appropriate string and then it worked.

    Also changing the output should be easy! :o We just have to do enemy_fort["HP"] -= damage. Right now we just have it print that without actually ever changing it.

    Well it'll be easy when you're able to get online, anyway!!! Was it on Tuesday that he's leaving?
    Uh... finals are in two weeks asdfjkl I haven't even started studying and aaaaaaaaaaaa
    enemy_fort = self.forts["".join([fort for fort in self.forts if fort != team])]

    Don't ask why you need the join because I really. don't. know.

    [19:34] <Kiruwing> ~use Giant Wheel
    [19:34] <kittybot> Kiruwing: 37

    ~reload PillowFort
    ~regteam Meowing Lights
    ~jointeam Meowing Lights
    ~regwpn Giant Wheel
    ~wpnwk Giant Wheel wood, alive
    ~wpnstrg Giant Wheel metal, stone
    ~startfort magic


    ~regteam Fire
    ~jointeam Fire
    ~startfort alive

    Closing your plugin now, just figured out that one mean problem!!
    I guess it should probably maybe work. Maybe :P

    also SUMMER it's WARM and SUNNY OUTSIDE and GRASS IS GROWING and ajhf jhf hjb I want school to end already; two more weeks auhgughg
    Yes! Yes I am! I don't really post a lot anymore but I come around and check up on the place. How've you been?
  • Loading…
  • Loading…
  • Loading…
Back
Top Bottom