-3

I wrote my code as normal but for some reason when it gets to the point before def jscript() it just stops. No errors or anything it just stops. Can someone help me pls. Sorry for all the code... Here is all my code to try out and then you will understand what is happening. I think the copy and paste messed up the indentation though.

def script():
            Wins = 0
            Fails = 0
            Energy = 20
            Fuel = 40
            Oxygen = 30
            Coins = 10
            Life = 100
            AlienLife = 250
            global Energy
            global Fuel
            global Oxygen
            global Coins
            global Life
            global Wins
            global Fails

            time.sleep(5)
        firstName = input("Hello! What is your first name? ") 
        surnameName = input(" And what is your surname? ")
        fullName = firstName + " " + surnameName
        print ("Ok then. Welcome,",fullName,"to the Age Of Space! Here you will have to drive your spaceship victoriously and survive all enemy threats. Your mission is to free Earth from the alien abduction!")
        time.sleep(7)
        print("Btw good luck in defeating the alien king! ;)")
        time.sleep(3)
        print("Your spaceship will take off in 5...")
        time.sleep(2)
        print("4...")
        time.sleep(1)
        print("3...")
        time.sleep(1)
        print("2...")
        time.sleep(1)
        print("1...")
        time.sleep(2)
        print ("BLAST OFF!!!")
        time.sleep(5)
        print("You are now in the depths of space. Commander please ensure that you keep safe during your journey. Good luck!")
        time.sleep(2)
        sleep = input("Commander, would you like to sleep now? If yes then we can take out your bed. ")
        if sleep == "yes":
            Energy = Energy + 5
            print("We have taken out your bed. The spaceship is on autopilot and you may now sleep.")
            time.sleep(4)
            print("2 weeks later...")
        else:
            Energy = Energy - 5
            print("Ok. It is all your choice. BUT you WILL lose energy. Lets carry on with the journey. You have",Energy,"energy remaining.")
            time.sleep(4)
        print("Commander, you have been extremely successful so far. Well done and keep it up!")
        time.sleep(6)
        direction = input("Oh no Sir! There is trouble ahead! Please make your decision quick. It's a matter of life and death. It is also a matter of chance! There are many asteroids ahead. You may either go forwards, backwards, left or right. Make your decision...before it's too late! ")  
        if direction == "left":
            Coins = Coins + 15
            Fuel =  Fuel - 15
            while True:
                print ("You have managed to pass the asteroids, you may now carry on. You have",Fuel,"fuel left.")
                break
                continue
        elif direction == "backwards":
            print("You have retreated and gone back to Earth. You will have to start your mission all over again.")
            time.sleep(2.5)
            print("The game will now restart.")
            time.sleep(2)
            print("Please wait...\n"*3)
            time.sleep(5)
            keep_playing = True
            while True:
                 script()
        elif direction == "forwards":
            Fails = Fails + 1
            print("You have crashed and passed away. Your bravery will always be remembered even if you did fail terribly. You have failed",Fails,"times.")
            time.sleep(3)
            ans = input("Do you want to play again? ")
            if ans == "yes":
                time.sleep(6)
                script()
            else:
                print("Our Earth is now an alien world...")
        else:
            Fuel =  Fuel - 10
            Coins = Coins + 15
            print("You have landed on a planet and have",Fuel,"fuel left.")
            time.sleep(1) 
            def myscript():
                Fuel = 30
                Oxygen = 30
                Coins = 25
                print("What do you want to buy? You have currently",Coins,"coins and",Fuel,"fuel.")
                print ("You have a choice between the following and may only buy one:")
                time.sleep(1)    
                pistol = 20
                print("A pistol for 20 coins")
                time.sleep(1)
                costfuel = 10
                print("15 fuel for 10 coins")
                time.sleep(1)
                shotgun = 40
                print("A shotgun for 40 coins")
                time.sleep(1)
                costoxygen = 10
                print("10 oxygen for 10 coins")
                time.sleep(1)
                costlife = 50
                print("or 5 life for 50 coins")
                time.sleep(1)
                choose = input("You may now choose which of the following you want - please type it in e.g fuel. ")
                if choose == "pistol":
                    while Coins < pistol:
                        print ("You cannot buy this as you do not have enough money. Please type in something else.")
                        time.sleep(4)
                        myscript()
                        break
                    else:
                        Coins = Coins - 20
                        print ("Thank you for purchasing the pistol! You have",Coins,"coins remaining.")
                elif choose == "fuel":
                    while Coins < costfuel:
                        print ("You cannot buy this as you do not have enough money. Please type in something else.")
                        time.sleep(4)
                        global Coins
                        myscript()
                        break
                    else:
                        Coins = Coins - 10
                        Fuel = Fuel + 15
                        print ("Thank you for purchasing the fuel! You have",Fuel,"fuel remaining and",Coins,"coins remaining.")
                elif choose == "shotgun":
                    while Coins < shotgun:
                        print ("You cannot buy this as you do not have enough money. Please type in something else.")
                        time.sleep(4)
                        global Coins
                        global Fuel
                        Coins = 15
                        Fuel = 45
                        myscript()
                        break
                    else:
                        Coins = Coins - 40
                        print ("Thank you for purchasing the shotgun! You have",Coins,"coins remaining")
                elif choose == "oxygen":
                    while Coins < costoxygen:
                        print ("You cannot buy this as you do not have enough money. Please type in something else.")
                        time.sleep(4)
                        global Coins
                        myscript()
                        break
                    else:
                        Coins = Coins - 10
                        Oxygen = Oxygen + 10 
                        print ("Thank you for purchasing the oxygen! You have",Coins,"coins remaining and",Oxygen,"oxygen remaining.")
                        global Coins
                        Coins = 15
                        global Oxygen
                        Oxygen = 40
                else:   
                    while Coins < costlife:
                        print ("You cannot buy this as you do not have enough money. Please type in something else.")
                        time.sleep(4)
                        myscript()
                        break
                    else:
                        Coins = Coins - 50
                        print ("Thank you for purchasing more life! You have",Coins,"coins remaining and",Life,"life remaining!")
            myscript()
        time.sleep(3.5)
        prin = input("Well done Commander! Bravo! You are doing excellent! Would you like to eat? ")
        if prin == "yes":
            Oxygen = Oxygen - 10
            print ("There is a lot of food in the cupboard please help yourself.")
        else:
            print ("Very well, hope you don't get hungry Sir.")
            time.sleep(2.5)
        papy = input("Would you like to go to sleep commander? ")
        if papy == "yes":
            Energy = Energy + 5
            print("Hope you have a great nap and fill yourself with enrgy Sir! Your bed has been taken out and you may now sleep.")
            time.sleep(6)
            print("15 hours later...")
            time.sleep(3.5)
            print("Sir! Sorry to interfere your sleep but you have landed on a planet!")
            def minescript():
                global Coins
                global Oxygen
                global Fuel
                print("What do you want to buy? You have currently",Coins,"coins and",Fuel,"fuel.")
                print ("You have a choice between the following and may only buy one:")
                time.sleep(1)    
                pistol = 20
                print("A pistol for 20 coins")
                time.sleep(1)
                costfuel = 10
                print("15 fuel for 10 coins")
                time.sleep(1)
                shotgun = 40
                print("A shotgun for 40 coins")
                time.sleep(1)
                costoxygen = 10
                print("10 oxygen for 10 coins")
                time.sleep(1)
                choose = input("You may now choose which of the following you want - please type it in e.g fuel. If you do not have enough money to buy anything type in 'nothing'. ")
                if choose == "pistol":
                    while Coins < pistol:
                        print ("You cannot buy this as you do not have enough money. Please type in something else.")
                        time.sleep(4)
                        minescript()
                        break
                    else:
                        Coins = Coins - 20
                        print ("Thank you for purchasing the pistol! You have",Coins,"coins remaining.")
                elif choose == "fuel":
                    while Coins < costfuel:
                        print ("You cannot buy this as you do not have enough money. Please type in something else.")
                        time.sleep(4)
                        myscript()
                        break
                    else:
                        Coins = Coins - 10
                        Fuel = Fuel + 15
                        print ("Thank you for purchasing the fuel! You have",Fuel,"fuel remaining and",Coins,"coins remaining.")
                elif choose == "shotgun":
                    while Coins < shotgun:
                        print ("You cannot buy this as you do not have enough money. Please type in something else.")
                        time.sleep(4)
                        minescript()
                        break
                    else:
                        Coins = Coins - 40
                        print ("Thank you for purchasing the shotgun! You have",Coins,"coins remaining")
                elif choose == "oxygen":
                    while Coins < costoxygen:
                        print ("You cannot buy this as you do not have enough money. Please type in something else.")
                        time.sleep(4)
                        minescript()
                        break
                    else:
                        Coins = Coins - 10
                        Oxygen = Oxygen + 10 
                        print ("Thank you for purchasing the oxygen! You have",Coins,"coins remaining and",Oxygen,"oxygen remaining.")
                else:        
                        print ("Hope you find something to buy next time :)")
            minescript()    
        else:
            Energy = Energy - 10
            print("Very well Sir. You have",Energy,"energy remaining now.")
        time.sleep(4)
        print("Now you will see a map of where you are and how close you are to the alien palace.")
        time.sleep(2)
        print("Please wait...")
        time.sleep(2)
        print("Please wait...")
        time.sleep(2)
        print("Please wait...")
        time.sleep(8)
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("ZZZZZZZZZZZZZZZZZZZZZ00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("ZZZZZZZZZZZZZZZZZZZZZ00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("                   ZZ00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("                   ZZ00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("                   ZZ00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("                   ZZ00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("                   ZZ00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("                   ZZ000000000000000000MMMM000000000000000000000000PPPPPPPPPP0000000000000000000000000000000000000000000000-00000000-0000000000000000000")
        print("                   ZZ000000000000000000MMMM000000000000000000000000P        P000000000000000000000000000000000000000000000- -000000- -000000000000000000")
        print("                   ZZ000000000000000000MMMM00000000MMM0000000000000P PLANET P00000000000000000000000000000000000000000000-   -0000-   -00000000000000000")
        print("      EARTH        ZZ0000000000000000000---------00MMM0000000000000P        P000000000000000000000000000000000*0000000000-    -000-   -00000 **     ** 0")
        print("(where you started)ZZ--------------------000MMM0--------------00000PPPPPPPPPP0000000000000000000000000000000*****00000000-  a -000-   -00000 ..     .. 0")
        print("                   ZZ00000000000000000000000MMM00000000000000-0000000000000000000000000IIIII0000000000000000*****00000000-  l -000-   -00000     oo    0")
        print("                   ZZ000000000000000000000000000000MMM0000000--------------------------I U I00000000000000000000000000000-  i -000-   -00000           0")
        print("                   ZZ000000000000000000000MMMMM0000000000000000000000000000000000000000IIIII00000000000000000000000000000-  e -000-   -00000 (_______) 0")
        print("                   ZZ000000000000000000000MMMMM00000000000000000000000000000000000000000000000000000000000000000000000000-  n -000-   -00000           0")
        print("                   ZZ000000000000000000000MMMMM0000000000000000000000000000000000000000000000000000000000000000000*000000-    -000- p -00000000000000000")
        print("                   ZZ0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000*****0000-    -000- a -00000000000000000")
        print("                   ZZ00000000000000000000000000000000000PPPPPPPPPP0000000000000000000000000000000000000000000000*****0000-    -000- l -00000000000000000")
        print("ZZZZZZZZZZZZZZZZZZZZZ00000000000000000000000000000000000P        P0000000000000000000000000000000000000000000000000000000-    -000- a -00000000000000000")
        print("ZZZZZZZZZZZZZZZZZZZZZ00000000000000000000000000000000000P PLANET P0000000000000000000000000000000000000000000000000000000-    -000- c -00000000000000000")
        print("00000000000000000000000000000000000000000000000000000000P        P0000000000000000000000000000000000000000000000000000000-    -000- e -00000000000000000")   
        print("00000000000000000000000000000000000000000000000000000000P        P00000000000000000000000000000000000000000000000000000000-  -00000- -000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000PPPPPPPPPP000000000000000000000000000000000000000000000000000000000--0000000-0000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        print("00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000")
        time.sleep(5)
        print("MMM = asteroids")
        time.sleep(1.5)
        print("U = where you are")
        time.sleep(1.5)
        print("---- = path")
        time.sleep(1.5)
        print("***** = alien security/alien guards ")
        time.sleep(6)
        print("Please ensure that you have reviewed the map - thank you.")
        print("Commander, you have progressed extremely well and will be well remembered in history. For your progress you have been awarded 100 extra coins! Please use it wisely if you get a chance. Remember you have",Life,"lives and the alien king has",AlienLife,"lives!")
        global Coins
        Coins = Coins + 100
        print("You now have",Coins,"coins.")
        p = input("You have " + str(Energy) + " energy left commander, would you like to go to sleep? ")
        if p == "yes":  
            print("Hope you have a great sleep THIS time :)")
            Energy = Energy + 2
        else:
            print("Very well.")
            Energy = Energy - 5
        if Energy == 0:
            print("You have run out of energy master! You must retreat now!")
            time.sleep(1)
            print ("Your mission is over. You have travelled back to Earth on autopilot. You were too tired to carry on.")
            time.sleep(2)
            print ("The game will now restart.")
            time.sleep(4)
            script()
        else:
            Fuel = Fuel - 5
            print("You have",Energy,"energy and",Fuel,"fuel left.")
            print("You are doing very well. Soon you will have to battle the alien guards so be prepared to loose some lives :). No pressure.")
            time.sleep(3)
            print("After an hour...")
            time.sleep(3)
            Fuel = Fuel - 5  
            if Energy == 0:
                print("You have run out of energy master! You must retreat now!")
                time.sleep(1)
                print ("Your mission is over. You have travelled back to Earth on autopilot. You were too tired to carry on.")
                time.sleep(2)
                print ("The game will now restart.")
                time.sleep(4)
                script()
            else:
                print("Sir! The ship has broken down. You have to go outside to fix it. As a consequence you will loose quite a bit of oxygen. You have",Oxygen,"oxygen left and",Energy,"energy left. Please make a choice between the following:")
                time.sleep(2)
                print("Repair fully - result in 10 oxygen loss and 10 energy loss.")
                time.sleep(2)
                print("Repair half - result in 5 oxygen loss and 5 energy loss. Then you will be able to finish it off the next day after sleeping.")
                time.sleep(2)
                print("Do not repair now - result in no loss of energy and oxygen but you will not be able to finish the repair the next day either.")
        def jscript():
            global Coins
            global Oxygen
            global Fuel
            repair = input("Please type in your choice. E.g. full or half or not now. ")
            if repair == "full":
                while Energy < 10:
                    print("You cannot carry out this option, sorry.")
                    time.sleep(3)
                    jscript()
                    break
                else:
                    Oxygen = Oxygen - 10
                    Energy = Energy - 10
                    print("The repair has been successful. You now have",Fuel,"fuel",Oxygen,"oxygen and",Coins,"remaining!")
            elif repair == "half":
                while Energy < 5:
                    print("You cannot carry out this option, sorry.")
                    time.sleep(3)
                    jscript()
                    break
                else:
                    Oxygen = Oxygen - 5
                    Energy = Energy - 5
                    print("The half repair has been successful. You now have",Fuel,"fuel",Oxygen,"oxygen and",Coins,"remaining!")
                    time.sleep(2)
                    print("Commander hopefully this will not seem too aggressive to you, but I think you HAVE to sleep now. The beds are ready so take a rest...")
                    Energy = Energy + 6
                    time.sleep(3)
                    print("The next day...")
                    time.sleep(3)
                    print("Congarats! The rest of the spaceship has been repaired successfully without any loss! ;)")
            else:
                print("There will be no repair done.")
                time.sleep(2.5)
                print("The next day...")
                time.sleep(3.5)
                foo = ['a'] * 65 + ['b'] * 35
                an = random.choice(foo)
                if an == "a":
                    print("hi")
                else:
                    print("SHing CHing")
    script()
wacraby
  • 11
  • 1
  • 8
  • 1
    Please correct your code indentation , it seems wrong – ᴀʀᴍᴀɴ Jan 10 '16 at 19:30
  • can u show me please – wacraby Jan 10 '16 at 19:31
  • by the way thats not the end of the code there is more but i did not put it – wacraby Jan 10 '16 at 19:33
  • See here : http://stackoverflow.com/questions/1024435/howto-fix-python-indentation – ᴀʀᴍᴀɴ Jan 10 '16 at 19:33
  • I think I answered your question, but your program is quite unclear of what it should do, so I tried my best to help. –  Jan 10 '16 at 19:40
  • If you could explain what the function should do and you should also do comments throughout your program so it is easier to read. –  Jan 10 '16 at 19:43
  • Whwt is happening is that the print ("") thing before the def jscript() is just stopping. So when I run the code it stops at the print ("Do not repair now - result in no loss of energy and oxygen but you will not be able to finish the repair the next day either.") point. AS you can see there is more code after the def bit saying input and so on. The thing is the code is supposed to carry on however it just stops at the point before the def() and doesnt carry on. It does not say error or anything it just shows the symbols >> – wacraby Jan 10 '16 at 19:59
  • sorry the symbols are >>> – wacraby Jan 10 '16 at 20:00

2 Answers2

1

I'm going to assume that this is what you are trying to get. You are not supposed to define a function inside if-else statement. You are just supposed to call it.

else:
    print("Sir! The ship has broken down. You have to go outside to fix it. As a consequence you will loose quite a bit of oxygen. You have",Oxygen,"oxygen left and",Energy,"energy left. Please make a choice between the following:")
    time.sleep(2)
    print("Repair fully - result in 10 oxygen loss and 10 energy loss.")
    time.sleep(2)
    print("Repair half - result in 5 oxygen loss and 5 energy loss. Then you will be able to finish it off the next day after sleeping.")
    time.sleep(2)
    print("Do not repair now - result in no loss of energy and oxygen but you will not be able to finish the repair the next day either.")* This is where the code stops
    jscript()

def jscript():
    global Coins
    global Oxygen
    global Fuel
    repair = input("Please type in your choice. E.g. full or half or not now. ")
    if repair == "full":
        while Energy < 10:
            print("You cannot carry out this option, sorry.")
            time.sleep(3)
            jscript()
            break
    else:
        Oxygen = Oxygen - 10
        Energy = Energy - 10
        print("The repair has been successful. You now have",Fuel,"fuel",Oxygen,"oxygen and",Coins,"remaining!")

Also, why are you calling the function inside itself and then do break it's pointless and then you do a while look that breaks after completing once. Remove all that it's pointless and doesn't do anything just use another if.

def jscript():
    global Coins
    global Oxygen
    global Fuel
    repair = input("Please type in your choice. E.g. full or half or not now. ")
    if repair == "full":
        if Energy < 10:
            print("You cannot carry out this option, sorry.")
            time.sleep(3)
        else:
            break
    else:
        Oxygen = Oxygen - 10
        Energy = Energy - 10
        print("The repair has been successful. You now have",Fuel,"fuel",Oxygen,"oxygen and",Coins,"remaining!")
  • Could you explain what supposed to happen and post entire code please –  Jan 10 '16 at 19:52
  • you got it right. After indenting the def() and everything after it still doesn't work. When I run it the last message that comes up is where the code stops. So it is like this: – wacraby Jan 10 '16 at 19:53
  • Do not repair now - result in no loss of energy and oxygen but you will not be able to finish the repair the next day either. >> – wacraby Jan 10 '16 at 19:53
  • define jscript at the top of your code, then start the main program afterwords. Also it might just be incorrect use of if statement in your program, so it goes to `if rapir== "full`, then goes to break every time –  Jan 10 '16 at 19:56
  • so how should i change the break – wacraby Jan 10 '16 at 20:01
  • I don't know because I don't know what you want to happen. You could change break to `print("Error!")` to see if that is actually your problem though –  Jan 10 '16 at 20:02
  • Could you paste your entire program into the question, so I can test it myself and post the fix –  Jan 10 '16 at 20:04
  • ok thanks ill check now. What I want to happen is for the code to carry on and ask the question Please type in your choice. E.g. full or half or not now. Then the user will input and then itll continue – wacraby Jan 10 '16 at 20:04
  • its too long what should i do? sorry im kinda new – wacraby Jan 10 '16 at 20:07
  • edit your question it is right under the python tag under your main question click the edit button and paste the entire code –  Jan 10 '16 at 20:11
  • Thank you it will be just a minute as I need to finish something up for my computer science class –  Jan 10 '16 at 20:14
  • @wacraby Wow, I'm sorry, but either you didn't past the code right or there is just too many errors that I don't have time to sort through sorry. If you could check to make sure it is right –  Jan 10 '16 at 20:23
  • try now just fix indentations – wacraby Jan 10 '16 at 20:27
  • @wacraby Sorry, but I don't have time to fix this there is a lot of errors maybe some other time. Check some of my programs on code review to get some kind of idea of how it should look. Click my name and there sjould be a tab that says codereview. again I'm sorry, really busy learning java my 4th language for computer science class –  Jan 10 '16 at 20:38
  • Thanks all for help :) – wacraby Jan 14 '16 at 21:58
  • @wacraby Did you figure it out? –  Jan 14 '16 at 22:40
1

There are several issues in your code, making it rather difficult to follow the logic and structure of it. So here are some comments on how to refactor your code into something more useful, whilst still keeping the same kind of game logic.

  • Introduce a print and sleep function – Introducing a function at top level to print message and sleep for a while would reduce your code drastically.
  • Using "Welcome {} to the Age Of Space".format(fullname) simplify string handling – This is in combination with the previous suggestion could result in the following function:

    def output_message(message, sleep_time):
        """Outputs a message, followed by a sleep period."""
    
        print(message)
        time.sleep(sleep_time)
    

    Which then can be used like:

    output_message("Welcome {}, to the Age Of Space!".format(fullName), 7)
    output_message("Good luck in defeating the alien king! ;)", 3)
    output_message("Your spaceship will take off in 5...", 2)
    output_message("4...", 1)
    output_message("3...", 1)
    output_message("2...", 1)
    
  • Gather functions at start of file – Even though it is legal to define functions at almost any level in Python, it is strongly adviced to define all the functions at the start of your file. In other words something like the following:

    import time
    
    def output_message(message, sleep_time):
       """My docstring."""
       ... code as before ...
    
    
    def script():
        ...
        code of script()
        ...
    
    def myscript():
        ... code of myscript ...
    
    def main():
        while True:
            start_mission()
            # Ask if user wants to restart game
            restart = input("Do you want to restart game? ")
    
            if restart == "no":
                break
    
    
    if __name__ == "__main__":
        main()
    

    As you can see all functions starts at beginning of line, and this is normal, as long as you're not defining class methods which would be one indentation level further in.

    PS! Stack exchange tip: After pasting in text into the edit box here at a Stack Exchange site, mark everything and hit Ctrl-K to properly indent the code.

  • Avoid sequential recursive function calling – That is instead of calling script() from within def script(), you should allow script to end, and then call it another time if the user opts to restart. This structure is depicted in previous code block.

    Similar structure should be applied to calling the minescript(), myscript() and possibly jscript(). All of these are by the way poorly named, and doesn't depict what is actually happening. It also seems like minescript() and myscript() are very similar, and should possibly be called something like buy_stuff().

  • Bug: You don't call jscript() outside of jscript(), and wrong indentation level – All the other inner functions you have, like minescript() and myscript follows this pattern:

    if something:
       ...
    elif something else:
       ...
    else
       ...
       def aFunction():
           ...
       aFunction()
    if yet_another_condition:
       ...
    

    But for jscript() you have moved the indentation out two levels, and you do not call jscript() after the definition.

  • Avoid strange loop when buying stuff – You have a strange concept of loops related to the inner functions, like this simplified version of minescript():

   def minescript():
       global Coins
       global Oxygen
       global Fuel
       print("What do you want to buy? You have currently",Coins,"coins and",Fuel,"fuel.")
       output_message("You have a choice between the following and  may only buy one:", 1)
       pistol = 20
       output_message("A pistol for 20 coins", 1)
       costfuel = 10
       print("15 fuel for 10 coins")
       choose = input("You may now choose which of the following you want - please type it in e.g fuel. If you do not have enough money to buy anything type in 'nothing'. ")
       if choose == "pistol":
           while Coins < pistol:
               output_message("You cannot buy this as you do not have enough money. Please type in something else.", 4)
               minescript()
               break
           else:
               Coins = Coins - 20
               print("Thank you for purchasing the pistol! You have",Coins,"coins remaining.")
       elif choose == "fuel":
           while Coins < costfuel:
               print ("You cannot buy this as you do not have enough money. Please type in something else.")
               time.sleep(4)
               myscript()
               break
           else:
               Coins = Coins - 10
               Fuel = Fuel + 15
               print ("Thank you for purchasing the fuel! You have",Fuel,"fuel remaining and",Coins,"coins remaining.")
       else:        
               print ("Hope you find something to buy next time :)")
   minescript() 

This is bad code because it calls it self recursively, instead of doing an internal loop until the user has either bought something the user can afford or chosen to buy nothing. A better code structure for buying stuff would be:

def minescript():
    global Coins
    global Oxygen
    global Fuel
    print("What do you want to buy? You have currently",Coins,"coins and",Fuel,"fuel.")
    output_message("You have a choice between the following and may only buy one:", 1)
    pistol = 20
    output_message("A pistol for 20 coins", 1)
    costfuel = 10
    print("15 fuel for 10 coins")
    while True:
        choose = input("You may now choose which of the following you want - please type it in e.g fuel. If you do not have enough money to buy anything type in 'nothing'. ")
        if choose == "pistol":
            if Coins < pistol:
                output_message("You cannot buy this as you do not have enough money. Please type in something else.", 4)
            else:
                Coins = Coins - pistol
                print("Thank you for purchasing the pistol! You have",Coins,"coins remaining.")
                break
        elif choose == "fuel":
            if Coins < costfuel:
                output_message("You cannot buy this as you do not have enough money. Please type in something else.", 4)
        else:
            Coins = Coins - costfuel
            Fuel = Fuel + 15
            print ("Thank you for purchasing the fuel! You have",Fuel,"fuel remaining and",Coins,"coins remaining.")
            break
    else:        
            print ("Hope you find something to buy next time :)")
            break
minescript() 

An even better version would be to keep the stuff available for buying in a list with corresponding price and use this to simplify the function even further.

def buy_stuff(items):
    global Coins
    global Oxygen
    global Fuel
    print("What do you want to buy? You have {} Coins, and {} fuel".format(Coins, Fuel))
    output_message("You have a choice between the following and may only buy one:", 1)
    for item in items:
        print("    {} : {} coins".format(item, items[item]))

    while True:
        choice = input("Type item you want to purchase or 'nothing'")
        if choice in items:
            if items[choice] > Coins:
                output_message("You don't have enough money. Try something else.", 4)
            else:
                Coins = Coins - items[choice]
                print("You bought: {}, and have {} coins left.".format(choice, Coins))
                break
        elif choose == "nothing":
            print ("Hope you find something to buy next time :)")                    break
        else:        
            print("Couldn't find that item. Use 'nothing' if you don't want to buy anything.")

 store_items = {
     'pistol': 20,
     'fuel': 15,
     'energy': 20
 }
 buy_stuff(store_items)

Code is untested, but you should get the gist of it. And it can be adapted to changing the different variables by utilizing tuples or similar.

Hopefully, these hints should help you get on the way to solving your issues, and simplify your code quite drastically. On a final note, you should also consider avoid using globals, and possibly simplify some of the messages or look into predefining some of the larger text parts to further enhance the focus on the game logic in your code instead of the "noisy" of all the text messages as it currently stands.

holroy
  • 3,047
  • 25
  • 41
  • Sorry to ask this but what do you mean by You don't call jscript() outside of jscript() and that you do not call jscript() after the definition? – wacraby Jan 11 '16 at 19:37
  • @wacraby ser the code excerpt in my answer, there the function definition `def minescript():` with code is followed by the call `minescript()`. The definition of jscript is **not** followed by a call... – holroy Jan 11 '16 at 23:24
  • i have done the same thing with jscript like with minescript. Sorry i do not get your point. – wacraby Jan 12 '16 at 17:24
  • @wacraby, ehh... No! You have `def jscript():` and loads of code, but you don't have the same `jscript()` as you do for the other functions. At least not in the code in the question. – holroy Jan 12 '16 at 17:26
  • I am soo soo sorry but i am new. If you could fix it and show me it will be much appreciated – wacraby Jan 12 '16 at 17:30
  • @wacraby, The quick and dirty fix is to add `jscript()` at the second to last line at the same indentation as the `def jscript()`. This might/should resolve the bug, but you should take all the other elements into account and rebuild it according to those as well. – holroy Jan 12 '16 at 17:36
  • @holroy wow, your answer to a specific programming problem looks like one of your code reviews. –  Jan 14 '16 at 22:43
  • @DeliriousSyntax HeHe... A good review, and solving programming issues are quite similar. At least in my world. Or, I kind of found a way of formatting I like. :-) – holroy Jan 14 '16 at 22:49