0

I'm working on this text based game for a school project, please keep in mind i've only just recently started python so i might be making a lot of mistakes sorry. Basically in my game there's different events that happen at certain locations which are shown as co-ordinates like theres a NPC interaction at coords (4,5) for example. I've made the events that will happen in each coords but when i run my program they won't get shown on the screen? Here's one event:

def event_1():
    global xpos, ypos
    if xpos == 2 and ypos == 2 or 4:
        typingPrint("""You've come across a bush of berries! They look safe enough..
       Would you like to:
       A- Eat one right now
       B- Store it in your inventory for later
       C- leave it as it is""")
        event_1_choice = typingInput("<<< ")
        if event_1_choice in answer_A:
            typingPrint("You've eaten a berry and gained 20 HP!!")
        elif event_1_choice in answer_B:
            typingPrint("You've stored the berry for later use")
            inventory.append("Berry")
        elif event_1_choice in answer_C:
            typingPrint("You decide to leave the berry as it is, better to be safe then sorry!!")
        else:
            print("Sorry? do you want the berries or not?")
            return event_1()


event_1()

When I run this program, none of the above shows? it just prints out the coords your on and this function doesn't occur? I'm not sure what else to try to make it work, Thank you in advance. Hope it makes sense. (Also just to note, the answer_a, b, c are all created variables to store the users answer)

shaji Fai
  • 1
  • 2
  • I don't think this is using `pygame`, so the tag is wrong. (Not edited as unsure) – 2e0byo Nov 22 '21 at 17:03
  • 4
    `if xpos == 2 and ypos == 2 or 4:` is a mistake. That's not how chained comparisons work in Python. It should be `if xpos == 2 and (ypos == 2 or ypos == 4)`. – Random Davis Nov 22 '21 at 17:03
  • (or more neatly `ypos in (2, 4)`, but I realise you were being explicit about the test) – 2e0byo Nov 22 '21 at 17:05
  • Are you following a particular tutorial? – Karl Knechtel Nov 22 '21 at 17:07
  • Incidentally writing the loop using a recursive fn call will *work*, but since python has no tail-call optimisation it's *usually* better to write an explicit loop. As it stands a determined user could crash the program by repeatedly entering nonsense, although it would take a while. – 2e0byo Nov 22 '21 at 17:08
  • nope, not following any tutorial and the xpos == 2 and (ypos == 2 or ypos == 4) didn't seem to work sadly – shaji Fai Nov 22 '21 at 17:08

0 Answers0