A Monster for Every Season: Summer 2
You can get A Monster for Every Season: Summer 2 now at Gumroad
Results 1 to 6 of 6

Thread: Python help?

  1. - Top - End - #1
    Orc in the Playground
     
    SwashbucklerGuy

    Join Date
    Nov 2010

    Default Python help?

    I have no idea why this is using invalid syntax. Any gitp coders why know why?

    Spoiler
    Show
    print("Welcome to the world of Lastreach. You are the great hero Edridian Dualscar. You are trapped in the lair of an angry dragon, which sleeps on a pile of gold. You have your cloth ROBES, a SWORD, and a STICK. You can ABSCOND, MOVE, ATTACK, say YES or NO, or USE one item on another")
    print("What do you do?")
    input()
    if input is ("KILL DRAGON") print("Attack LEGS, CHEST or HEAD")
    if input is ("TAKE GOLD") print("The dragon kills you for stealing its gold.") quit
    if input is not ("TAKE GOLD") or ("KILL DRAGON") or ("USE ROBES on DRAGON") or ("USE ROBES on SWORD") or ("USE STICK on SWORD") or ("Use SWORD on ROBES") or ("ABSCOND") or ("USE SWORD on STICK")
    if input is ("USE robes on DRAGON") print(" The dragon declines the offering. It kills you") quit
    if input is ("USE ROBES on SWORD") print("You cut your robes. Dumbass. The dragon eats you for being such a moron") quit
    if input is ("USE STICK ON SWORD") print("You now have a longer sword While you were working on that, the dragon sneaks up on you. You die.") quit
    if input is ("USE SWORD on STICK") print("You cut a stick. Dumbass.") quit
    input
    if input is not("KILL LEGS") print("The dragon stomps you flat.It pinches you all over.") quit
    if input is("KILL LEGS") print("The dragon is crippled.Attack the CHEST or HEAD?")
    input()
    if input ("KILL HEAD") print("You stab the dragon through the eye.viciously. You can now take gold from the dragon's hoard.")
    input()
    if input ("TAKE GOLD") print("You now have 100 gold") print("You leave the dragon's lair")
    print("You are on a dusty road. A Highwayman appears.)"
    input()
    if input() = ("KILL highwayman") print("He's dead, would you like to go on?") else print("You get stabbed.")quit
    input() if input() = ("MOVE") print"(You go forward") else print("You sit there like a moron. <") quit
    if input()= ("MOVE") print ("You go forward") else print("You sat there like a moron for years. You grow a long beard, and eventually die of old age.")quit


    My Victoria 2 AAR: Nate Jackson vs. Texas (No relation to any other Nate Jacksons)
    http://www.giantitp.com/forums/showthread.php?t=277079



    Spoiler
    Show

    Spoiler
    Show

  2. - Top - End - #2
    Barbarian in the Playground
     
    Selpharia's Avatar

    Join Date
    Sep 2011
    Gender
    Female

    Default Re: Python help?

    I'm not all that familiar with Python, but one of your input() statements lacks a (), right after "USE SWORD on STICK"
    This Minase Iori avatar is a masterwork by Qwernt

    DS Friend Code for Pokemon Trades and such. 1549 7971 5718

  3. - Top - End - #3
    Ogre in the Playground
     
    Bryn's Avatar

    Join Date
    Oct 2005
    Location
    England

    Default Re: Python help?

    Only ever slightly dabbled in Python, but which version are you using? If you're not in Python v3+ then print is a statement, not a function.

    I'm not sure if this is a thing in Python, but you don't seem to be storing result of input in any variable. Should it not be something like input = input() (although I wouldn't want to call the variable input to avoid confusion with the function anyway)? However, if Python automatically stores the result in a variable input, that doesn't matter.

    Also, you have some inconsistency in how you're using if statements. Assuming most of them use the correct syntax, should e.g. if input ("KILL HEAD") not be if input is ("KILL HEAD")? Further, as a style thing, I'm pretty sure you don't need to enclose all your strings in brackets!

    For a game like this, I'm not sure Python is the best language - it looks like you could do this kind of game much more easily in Twine. Of course, if you're doing this to learn Python, that's not very useful

    To begin with, I would recommend trying to do something smaller - just implement one option, make sure you have the syntax right, before filling out a long list like you have here.

    Incidentally, I feel you could probably structure your code more clearly than a bunch of if statements. You might be better off (more easy to maintain/extend the code) having a data structure of commands and associated outputs.
    Last edited by Bryn; 2013-08-03 at 01:09 PM.

  4. - Top - End - #4
    Colossus in the Playground
     
    BlackDragon

    Join Date
    Feb 2007
    Location
    Manchester, UK
    Gender
    Male

    Default Re: Python help?

    I'm not overly familiar with Python either, but one thing I *do* know about it is that indenting is part of the syntax of the language, so could it be a problem with the lack of indenting in your code?
    Last edited by factotum; 2013-08-03 at 03:35 PM.

  5. - Top - End - #5
    Orc in the Playground
     
    SwashbucklerGuy

    Join Date
    Nov 2010

    Default Re: Python help?

    Thanks. You guys were quite helpful.
    My Victoria 2 AAR: Nate Jackson vs. Texas (No relation to any other Nate Jacksons)
    http://www.giantitp.com/forums/showthread.php?t=277079



    Spoiler
    Show

    Spoiler
    Show

  6. - Top - End - #6
    Troll in the Playground
     
    NecromancerGirl

    Join Date
    Nov 2008
    Location
    Bristol, UK

    Default Re: Python help?

    It looks like you're using is incorrectly. is is used to test object identity, when you actually want to test for equivalence.

    But that's a potential bug, not an error. I'm afraid I don't know Python syntax that well either.

    Quote Originally Posted by factotum View Post
    I'm not overly familiar with Python either, but one thing I *do* know about it is that indenting is part of the syntax of the language, so could it be a problem with the lack of indenting in your code?
    That's because it was posted without [code] tags, I think, not because it wasn't originally indented.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •