LOUNGE all new asksnapzu ideasforsnapzu newtribes interesting pics videos funny technology science technews gaming health history worldnews business web research entertainment food living internet socialmedia mobile space sports photography nature animals movies culture travel television finance music celebrities gadgets environment usa crime politics law money justice psychology security cars wtf art google books lifetips bigbrother women apple kids recipes whoa military privacy education facebook medicine computing wildlife design war drugs middleeast diet toplists economy fail violence humor africa microsoft parenting dogs canada neuroscience architecture religion advertising infographics sex journalism disaster software aviation relationships energy booze life japan ukraine newmovies nsa cannabis name Name of the tribe humanrights nasa cute weather gifs discoveries cops futurism football earth dataviz pets guns entrepreneurship fitness android extremeweather fashion insects india northamerica
+3 3 0
Published 3 years ago with 12 Comments

Join the Discussion

  • Auto Tier
  • All
  • 1
  • 2
  • 3
Post Comment
  • [Deleted Profile] (edited 3 years ago)

    [This comment was removed]

  • Wenjarich
    +3

    So it would seem the introduction box felt this was too many words :P so I'll put the explaination here.

    Ok so I'm using python to write the start of a mock text based rpg game. Just wanted to do the the character creation part. It's a really simple thing I came up with that I felt I could do with what I have learnt so far. All it does is asks you what your name is, what your race is, and what your class is (last two chosen from three options each) and then assigns different stats variables accordingly that could be used later if you wanted.

    As you’ll see I have a file for the actual program and a file, called ch_creation, which I created to keep all the functions I use because it was all getting quite messy and figured it would be neater to just call the functions when needed.

    At the moment it does exactly what I want it to do, print("YAY!, go team Wenjarich!"), as long as the person using it chooses the options they are given to choose from (i.e. Race and Class) as you can see.

    So I figured that if the 'player' answers something stupid then all I need to do is have a something along the lines of..

    print( " \'Why do you waste my time like this? \' ... Stranger walks off")

    print( "You lose!")

    Then something to tell the program to end. (THIS IS WHAT I CAN”T WORK OUT!!)

    For the life of me though I can't find a solution online that will do this for me even though I’m going to look really stupid because I feel it’s probably a simple command.

    I was at first going to have them “simply” answer the question again but realized that involes for/while loops which I haven’t yet learnt.

    • jmcs
      +2

      You can use sys.exit() or just exit(). The first one is the "right" way to do it, but the second one also works for the reference implementation of python.

      • Wenjarich (edited 3 years ago)
        +2

        I tried sys.exit() before, and just tried it again and got the following error,

        Traceback (most recent call last):

        File "C:\Python34\Programs\Practice\Silly Test Game.py", line 23, in <module>

        race = ChCreation.chkrace(r)

        File "C:\Python34\Programs\Practice\ChCreation.py", line 12, in chkrace

        sys.exit()

        NameError: name 'sys' is not defined

        but I also now just tried exit() on it's own and it worked :)

        Thanks for the help! I know it was a small error to fix, but it'ts cool to me that it now works the way I want it to. I can now move on content that I achieved what I wanted to. :P

        Plus I may just come back and keep adding onto it as I go.

        • tefids
          +2

          Sounds like you got it working, but if you are curious as to why "sys.exit()" doesn't work, it sounds like you haven't imported the sys module. To do this simply place "import sys" at the top of the file. Hope this helps.

          • Wenjarich
            +3

            Oh I see, thanks :)

            • redalastor
              +2

              You pretty much always need to import things first : https://xkcd.com/353/ :D

            • Wenjarich
              +2
              @redalastor -

              I'm extremely tempted to try typing import antigravity into my code now :D

            • redalastor
              +3
              @Wenjarich -

              Actually, do try it. It links you to that comic.

              Also try

              import this
              
            • jmcs
              +1
              @redalastor -

              That should be in every tutorial even before the hello world.

            • redalastor
              +2
              @jmcs -

              Tutorials are often lacking. For instance, none seems to deal virtual environments, one of the most important concepts of python.

            • jmcs
              +1
              @redalastor -

              That's probably because before python 3.3 virtual environments were a third party solution and not part of the standard library. When we finally get good python 3 tutorials maybe they'll include venv.

Here are some other snaps you may like...