Python Forum
Nothing happens - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Game Development (https://python-forum.io/forum-11.html)
+--- Thread: Nothing happens (/thread-16899.html)



Nothing happens - jjmaster3001 - Mar-19-2019

Hi, when I run this script, it comes up with nothing, no words or anything. Is there something I am doing wrong, and what is it?
def main_game():
    inv = [ ]
    print("You wake up in a forest, and don't know where you are,")
    a = input ("Type 'A' to build a shelter, 'B' to look for shelter, or 'C' to look for food: ")
    if a == "A":
        print("You come across some pieces of ply wood, and some stones up on a hill")
        a1 = input("Type 'A' to use the wood, or 'B' to use the stones: ")
        if a1 == "A":
            have_shelter = True
            print("the wood seems strong and durable, you start using it to build a shelter, you see a storm in the distance.")
            print("your shelter is successful and looks good, it defends well against the storm.")
            a2 = input("to take apart your shelter type 'A', type 'B' to leave it as is: ")
            if a2 == "A":
                have_shelter = False
                inv.append("wood")
                print("this is your inventory")
                print(inv)
                print("You now have a shelter to come back to")
                print("you see a man with a gun running at you, he trys to hit you with it.")
                a3 = input("To block with the wood, type 'A', type 'B' to not.")
                if a3 == "B":
                    print("You stand there, while he beats you to death.")
                if a3 == "A":
                    if have_shelter == True:
                        print("You reach for the wood, but it is connected to your shelter, he beats you to death")
                    if have_shelter == False:
                        print("You take your wood and block his attack, you break the board over his head, he dies.")
                        print("You pick up the gun")
                        inv.remove("wood")
                        inv.append("gun")
                        print(inv)
                        main_game()
            if a2 == "B":
                print("You now have a shelter to come back to")
                print("you see a man with a gun running at you, he trys to hit you with it.")
                a4 = input("To block with the wood, type 'A', type 'B' to not.")
                if a4 == "B":
                    print("You stand there, while he beats you to death.")
                if a4 == "A":
                    if have_shelter == True:
                        print("You reach for the wood, but it is connected to your shelter, he beats you to death")
                    if have_shelter == False:
                        print("You take your wood and block his attack, you break the board over his head, he dies.")
                        print("You pick up the gun")
                        inv.remove("wood")
                        inv.append("gun")
                        print(inv)
        if a1 == "B":
            print("You start to build your shelter, when you see a storm coming your way.")
            print("When your almost done building, the stones fall leaving you with nothing. The storm knocks a tree over, it falls on you, you die.")
    if a == "B":
        print("You come across a cave, a cabbin, and a teepee.")
        b1 = input("Type 'A' to go to the cave, 'B' to go to the cabbin, or 'C' to the teepee: ")
        if b1 == "A":
            print("You go into the cave and see a dark shadow, reconizing it as a bear, you start to run.The bear grabs you and rips you apart. You die")
        if b1 == "B":
            ("you go into the cabbin, when you see someone, he looks scared and is holding a rifle towrds you.")
            b2 = input("to defuse the tention, type 'A', type 'B' to run: ")
            if b2 == "A":
                print("you say 'I dont want to hurt you,' he replies 'I can't trust you' and shoots you. you die")
            if b2 == "B":
                print("you run, he shoots you in the back. you die")



RE: Nothing happens - Larz60+ - Mar-19-2019

what are you expecting?


RE: Nothing happens - jjmaster3001 - Mar-19-2019

To do what the code says, print(“you wake up in...”)


RE: Nothing happens - Larz60+ - Mar-19-2019

You never execute the function.
after last line, add main_game()

or better yet:
if __name__ == '__main__':
    main_game()



RE: Nothing happens - jjmaster3001 - Mar-19-2019

I just tried it, it doesn’t work


RE: Nothing happens - Larz60+ - Mar-19-2019

Quote:I just tried it, it doesn’t work
This tells us nothing.
see: https://python-forum.io/misc.php?action=help&hid=19

I tried it, and here's the code and (begining run results):

def main_game():
    inv = [ ]
    print("You wake up in a forest, and don't know where you are,")
    a = input ("Type 'A' to build a shelter, 'B' to look for shelter, or 'C' to look for food: ")
    if a == "A":
        print("You come across some pieces of ply wood, and some stones up on a hill")
        a1 = input("Type 'A' to use the wood, or 'B' to use the stones: ")
        if a1 == "A":
            have_shelter = True
            print("the wood seems strong and durable, you start using it to build a shelter, you see a storm in the distance.")
            print("your shelter is successful and looks good, it defends well against the storm.")
            a2 = input("to take apart your shelter type 'A', type 'B' to leave it as is: ")
            if a2 == "A":
                have_shelter = False
                inv.append("wood")
                print("this is your inventory")
                print(inv)
                print("You now have a shelter to come back to")
                print("you see a man with a gun running at you, he trys to hit you with it.")
                a3 = input("To block with the wood, type 'A', type 'B' to not.")
                if a3 == "B":
                    print("You stand there, while he beats you to death.")
                if a3 == "A":
                    if have_shelter == True:
                        print("You reach for the wood, but it is connected to your shelter, he beats you to death")
                    if have_shelter == False:
                        print("You take your wood and block his attack, you break the board over his head, he dies.")
                        print("You pick up the gun")
                        inv.remove("wood")
                        inv.append("gun")
                        print(inv)
                        main_game()
            if a2 == "B":
                print("You now have a shelter to come back to")
                print("you see a man with a gun running at you, he trys to hit you with it.")
                a4 = input("To block with the wood, type 'A', type 'B' to not.")
                if a4 == "B":
                    print("You stand there, while he beats you to death.")
                if a4 == "A":
                    if have_shelter == True:
                        print("You reach for the wood, but it is connected to your shelter, he beats you to death")
                    if have_shelter == False:
                        print("You take your wood and block his attack, you break the board over his head, he dies.")
                        print("You pick up the gun")
                        inv.remove("wood")
                        inv.append("gun")
                        print(inv)
        if a1 == "B":
            print("You start to build your shelter, when you see a storm coming your way.")
            print("When your almost done building, the stones fall leaving you with nothing. The storm knocks a tree over, it falls on you, you die.")
    if a == "B":
        print("You come across a cave, a cabbin, and a teepee.")
        b1 = input("Type 'A' to go to the cave, 'B' to go to the cabbin, or 'C' to the teepee: ")
        if b1 == "A":
            print("You go into the cave and see a dark shadow, reconizing it as a bear, you start to run.The bear grabs you and rips you apart. You die")
        if b1 == "B":
            ("you go into the cabbin, when you see someone, he looks scared and is holding a rifle towrds you.")
            b2 = input("to defuse the tention, type 'A', type 'B' to run: ")
            if b2 == "A":
                print("you say 'I dont want to hurt you,' he replies 'I can't trust you' and shoots you. you die")
            if b2 == "B":
                print("you run, he shoots you in the back. you die")

if __name__ == '__main__':
    main_game()
output:
Output:
You wake up in a forest, and don't know where you are, Type 'A' to build a shelter, 'B' to look for shelter, or 'C' to look for food: A You come across some pieces of ply wood, and some stones up on a hill Type 'A' to use the wood, or 'B' to use the stones: B You start to build your shelter, when you see a storm coming your way. When your almost done building, the stones fall leaving you with nothing. The storm knocks a tree over, it falls on you, you die.



RE: Nothing happens - jjmaster3001 - Mar-19-2019

Where do you use ___name___


RE: Nothing happens - ichabod801 - Mar-19-2019

(Mar-19-2019, 03:51 PM)jjmaster3001 Wrote: Where do you use ___name___

The __name__ variable is provided by the system. If the module is imported by another module, it's value is the name of the file (without the extension). If it is run from the command line, it's value is '__main__'. It's a common Python technique to have code that isn't run when the module is imported.

BTW, you really need to look at my text adventure tutorial.


RE: Nothing happens - jjmaster3001 - Mar-19-2019

I used to be very good at this a coupled years ago. Recently I’ve been getting back into it.

It’s still not working


RE: Nothing happens - jjmaster3001 - Mar-19-2019

I fixed it