Click here to Skip to main content
15,909,193 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have this variable to track in which room you are, lobby is 1, Stairs is 2, hallway is 3, etc. it gets updated by normal math from raw_input

Python
currenKamer = 1


This is the code which displays where you are in where you could move, but it returns "hier kan je naartoe []". What am I missing?

Python
def showRoom(self):
    #kamer
    print(20 * "-")
    print("Hier ben je: " + kamers[currentKamer]["naam"])
    print("hier kan je naartoe: %s ") % [i['naam'] for i in kamers.values() if i.get('currentKamer',None) ]
    #leuk zinnetje per kamer
    if "note" in kamers[currentKamer]:
        print (20 * "-")
        print("--" + kamers[currentKamer]["note"])
    print(20 * "-")


What I have tried:

Python
[i['naam'] for i in kamers.values() if i.get == currenKamer ]

and
Python
[i['naam'] for i in kamers.values() if i.get(currentKamer) ]

Both return nothing but []
Posted
Updated 16-Jan-17 9:19am
Comments
Member 12952906 16-Jan-17 15:00pm    
I forgot this!, This is the room layout

kamers = {

            1 : {  "naam"  : "de Lobby" ,
                   "trap"  : 2,
                   "gangrechtdoor" : 3 }  ,

            2 : {  "naam"  : "de Trap" ,
                   "lobby"  : 1,
                   "note"  : "Terwijl je de trap oploopt hoor je in de verte Henk van Ommen schreeuwen" }  ,            

            3 : {  "naam"  : "de Gang rechtdoor" ,
                   "lobby" : 1,
                   "gymzaal" : 4, 
                   "concergie"  : 5,
                   "gangaula"  : 6 } ,
                   
            4 : {  "naam"  : "de Gymzaal" ,
                   "gangrechtdoor" : 3 } ,
            
            5 : {  "naam"  : "de Concierge" ,
                   "raamwim" : 9,
                   "gangrechtdoor" : 3 } ,
            
            6 : {  "naam"  : "de Gang rii aula" ,
                   "gangrechtdoor" : 3,
                   "juul" : 7 } ,
                   
            7 : {  "naam"  : "het Hokje van Juul" ,
                   "gangaula" : 6,
                   "kantine" : 8 } ,
            
            8 : {  "naam"  : "de Aula kantine" ,
                   "juul" : 7,
                   "raamwim" : 9 } ,
            
            9 : {  "naam"  : "het Loerraampje van wim" ,
                   "kantine" : 8,
                   "concierge" : 5 }
         }

1 solution

Based on your room layout in your comment, your code, and my ability to speak Dutch, it looks like you want to get all values that are not "naam" or "note" and then fetch the names from "kamers" based on these IDs.

I would restructure the layout to make things less complicated. I recommend a layout like this:
Python
kamers = {
    1: { "naam": "de Lobby", "adjacent": [2, 3] }, ...
}
Now you can just use the adjacent value to figure out what rooms you can go to.

You can do that like this:
Python
[kamers[i]['naam'] for i in kamers[currentKamer]['adjacent']]
for i in kamers[currentKamer]['adjacent'] iterates over each integer in the 'adjacent' list of the value in "kamers" with 'currentKamer' as key. Then kamers[i]['naam'] selects the name for the room with key i.
 
Share this answer
 
Comments
Member 12952906 16-Jan-17 15:27pm    
Dear ProgramFOX,

Yes that is what I also would think of, but then the movement system doesn't work, do you want to see the complete code? please visit (https://github.com/marcoburgman/HBLPythonRPG)

already a lot of thanks for helping me!
Thomas Daniels 16-Jan-17 15:30pm    
If the movement code stops working then, I recommend to have both 'adjacent' and your other values. Then both the movement and the 'recognition' system work fine.
Thomas Daniels 16-Jan-17 15:30pm    
In that case I recommend to have both 'adjacent' and the other variables you need. Then both the 'movement' and 'recognition' system will work fine.

(Edit: sorry for doubly posting, my first comment didn't show up at first)
Member 12952906 16-Jan-17 15:33pm    
No problem, well It will be coding and coffee for me the next hour! thanks for your wisdom! If it all works perfectly I will accept your solution ;)! btw funny you recognized the Dutch
Thomas Daniels 16-Jan-17 15:34pm    
You're welcome.

It's my native language ;P I live in Flanders.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900