Strange error on text based game thing.

This is the place for queries that don't fit in any of the other categories.

Strange error on text based game thing.

Postby spamynator_1 » Sat Oct 19, 2013 10:02 pm

I am making a text based game and i ran into a strange error that i cant seem to get by. Every time you type a direction i want the randomly generated number in biomegen to define the probability of being in each biome. my code is:
Code: Select all
import random
print("Welcome to shitstorm")
print("For list of commands, type 'help'")
VARIABLE = "CHODE"
class Game(object):
    def __init__(self):
        self.state = "PLAY"
        self.oldbiome = 1
        self.done = False
        #Bars
        self.health = 100
        self.stamina = 100
        self.strength = 100
        self.mana = 100
        #enemyBars
        self.xhealth = 100
        self.xstamina = 100
        self.xstrength = 100
        self.xmana = 100
        self.xdouchebaggery = 0
        #Location
        self.locx = 0
        self.locy = 0
         #Surroundings
        self.biome = 0
        self.trees = False
        self.cave = False
        self.rocks = False
        #Print Biome
        self.printbiome = ""
        #Print Surroundings
        self.printtree = "There are some trees around"
        self.printcave = "There is a cave opening"
        self.printrocks = "There are some rocks around"

    def control(self):
        while not self.done:
            self.input_loop()
       
    def input_loop(self):
        Q = raw_input(": ")
        if Q == ("help"):
            print("This game is made as if it were an actual grid of areas. Everything is based on randomly generated numbers. The commands are: north, south, east, west, stats")
        elif Q == "stats":
            print("Your health is: ")
            print(self.health)
            print("Your stamina is: ")
            print(self.stamina)
            print("Your strength is: ")
            print(self.strength)
            print("Your mana is: ")
            print(self.mana)
        elif Q == "north":
            self.locy += 1
            self.biomegen()
            self.treegen()
            self.cavegen()
            self.xbiome
            print(self.printbiome)
            self.checktree()
            self.checkcave()
            self.checkrocks()
        elif Q == "south":
            self.locy -= 1
            self.biomegen()
            self.treegen()
            self.cavegen()
            self.xbiome
            print(self.printbiome)
            self.checktree()
            self.checkcave()
            self.checkrocks()
        elif Q == "east":
            self.locx += 1
            self.biomegen()
            self.treegen()
            self.cavegen()
            self.xbiome
            print(self.printbiome)
            self.checktree()
            self.checkcave()
            self.checkrocks()
        elif Q == "west":
            self.locx -= 1
            self.biomegen()
            self.treegen()
            self.cavegen()
            self.xbiome
            print(self.printbiome)
            self.checktree()
            self.checkcave()
            self.checkrocks()

    def biomegen(self):
        neegs = random.randint(0,100)
        if neegs < 40:
            self.biome = 1
        elif neegs < 60:
            self.biome = 2
        elif neegs < 80:
            self.biome = 3
        elif neegs < 100:
            self.biome = 4

    def treegen(self):
        trees = random.randint(0,7)
        if trees == 7:
            self.trees = True
        elif trees != 7:
            self.trees = False

    def cavegen(self):
        cave = random.randint(0,25)
        if cave == 25:
            self.cave = True
        elif cave != 25:
            self.cave = False

    def rockgen(self):
        rocks = random.randint(0,7)
        if rocks == 7:
            self.cave = True
        elif rocks != 7:
            self.cave = False

    #Geographical Features
    def xbiome(self):
        if self.biome == 1:
            self.printbiome = "You are in a grassy field"
        elif self.biome == 2:
            self.printbiome = "You are in a forest"
            self.trees = True
        elif self.biome == 3:
            self.printbiome = "You are in mountains"
            self.rocks = True
        elif self.biome == 4:
            self.printbiome = "You are by a lake"

    def checktree(self):
        if self.trees == True:
            print(self.printtree)

    def checkcave(self):
        if self.cave == True:
            print(self.printcave)

    def checkrocks(self):
        if self.rocks == True:
            print(self.printrocks)

while VARIABLE == "CHODE":
    global dong
    exe = Game()
    exe.control()

the error is:
Code: Select all
line 41, in input_loop
    Q = raw_input(": ")
EOFError: EOF when reading a line


Help is appreciated thankyou and godbless you all and godbless our world.
spamynator_1
 
Posts: 63
Joined: Sun Mar 03, 2013 12:45 am

Re: Strange error on text based game thing.

Postby dboxall123 » Sat Oct 19, 2013 10:19 pm

Just copied and pasted it - worked fine.
dboxall123
 
Posts: 108
Joined: Fri Jul 12, 2013 5:28 pm

Re: Strange error on text based game thing.

Postby micseydel » Sat Oct 19, 2013 10:30 pm

Are you running this in an IDE? Are you giving it any input, or does it happen before you have the chance? By the way, it looks like you're using Python 3 so you don't need to inherit from Object explicitly. Also, you don't need these parenthesis
Code: Select all
if Q == ("help"):

Besides that, I recommend against global variables as well as calling a constant "VARIABLE".

I also feel like I need to point out the irony between the foul language in your code and invocation of god later on.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1179
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA

Re: Strange error on text based game thing.

Postby spamynator_1 » Sat Oct 19, 2013 10:37 pm

The issue is that when you execute the code and type in a command like "north" it is supposed to return self.biome and then self.trees or rocks and so on. It does not display the biome because the value of self.printbiome = "". the error blits breifly while killing the process.
spamynator_1
 
Posts: 63
Joined: Sun Mar 03, 2013 12:45 am

Re: Strange error on text based game thing.

Postby spamynator_1 » Sun Oct 20, 2013 11:58 pm

I have resolved this issue i just skipped a few steps in the biome process!
spamynator_1
 
Posts: 63
Joined: Sun Mar 03, 2013 12:45 am

Re: Strange error on text based game thing.

Postby micseydel » Mon Oct 21, 2013 2:27 am

I delete the other post since the code is basically the same. Stick to this thread for this project.
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1179
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Coding Help

Who is online

Users browsing this forum: Google [Bot], snippsat and 3 guests