jeudi 19 avril 2018

IF statements made redundant by ELSE statements

I'm having a go at my first draft of a game (the point of this draft is function over complexity of code so please don't go into how I can condense the code or make it more efficient, that'll come later) and part of that is having characters in each location of the game but I want this to be random. I've added a fair few IF statements to my location function so it tells you which character is in the room and then assigns that character to a variable I've called the Identifier so the game lets you talk to that character. However if there is nobody in the location then there's nobody to talk to so it needs an ELSE statement at the end but if I add an ELSE statement, for some reason I can't work out or find, it makes all of the IF statements totally redundant and makes it so that no matter what, it will always say there's nobody to talk to. If I remove this ELSE statement then the game will crash if you try and talk in a location where there are no characters. How do I fix this?? Many thanks in advance

if murderer.location == "Atrium":
    print(murderer.name, "is stood in here, waiting")
    identifier = murderer
if innocent1.location == "Atrium":
    print(innocent1.name, "is stood in here, waiting")
    identifier = innocent1
if innocent2.location == "Atrium":
    print(innocent2.name, "is stood in here, waiting")
    identifier = innocent2
if innocent3.location == "Atrium":
    print(innocent3.name, "is stood in here, waiting")
    identifier = innocent3
if innocent4.location == "Atrium":
    print(innocent4.name, "is stood in here, waiting")
    identifier = innocent4
if innocent5.location == "Atrium":
    print(innocent5.name, "is stood in here, waiting")
    identifier = innocent5
if innocent6.location == "Atrium":
    print(innocent6.name, "is stood in here, waiting")
    identifier = innocent6
if innocent7.location == "Atrium":
    print(innocent7.name, "is stood in here, waiting")
    identifier = innocent7
if body == "Atrium":
    print("Brad's dead body lies in the middle of the floor")
    identifier = ei
else:
    identifier = ei

Aucun commentaire:

Enregistrer un commentaire