Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Complex Long codes
#4
ayaz786amd Wrote:why its not like Line32?

Because line 32 is a conditional (which makes a choice as to whether or not to execute a block of code), and line 33 is an assignment (which assigns a value to a variable).

ayaz786amd Wrote:whats going on? what is each part of this line

In the line current_room = rooms[current_room[command]], the first step is looking up the key in 'command' in the dictionary current_room. That value is then used as a key in the rooms dictionary, and that value is assigned to current_room.

In more abstract terms, current_room is a dictionary of room IDs keyed to directions. The direction keys return the room IDs that you would get to going in that direction. Rooms is a bunch of dictionaries like current_room keyed to their room IDs. So you use the direction (command) to get the next room ID from current_room, and then get use that room ID to get the details on the room from rooms.

ayaz786amd Wrote:what is rooms in this line of code

It is a dictionary containing information on all of the rooms in the game, as described above. If you look at the definition of rooms at the top of the code, you will see that rooms['empty'] refers to a room named 'an empty room', connected to the bedroom and the temple, with the text description 'The stone floors and walls and cold and damp.'.

As I said, that tutorial glosses over a lot of stuff. But most of that is basic stuff that you should know before attempting a to write code that complicated.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Messages In This Thread
Complex Long codes - by ayaz786amd - Dec-14-2018, 07:40 AM
RE: Complex Long codes - by ichabod801 - Dec-14-2018, 01:57 PM
RE: Complex Long codes - by ayaz786amd - Dec-15-2018, 08:20 AM
RE: Complex Long codes - by ichabod801 - Dec-15-2018, 02:25 PM
RE: Complex Long codes - by ayaz786amd - Dec-21-2018, 04:48 AM
RE: Complex Long codes - by ichabod801 - Dec-21-2018, 02:37 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020