Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[Python] Help with 'Appending' Strings to Lists

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
phantom7748
How do I cheat?
Reputation: 0

Joined: 11 May 2012
Posts: 1

PostPosted: Fri May 11, 2012 10:31 am    Post subject: [Python] Help with 'Appending' Strings to Lists Reply with quote

So, before you harp on me for being a terrible coder, I'm new to Python, so please excuse my mistakes. (I'm also only 14, so I'm not a super genius...) I'm trying to write a simple program using tuples to loop around, and I'm trying to set an inventory in place. However, I haven't found an efficient way add an item to a base list whenever I activate something, etc. Here's the code, I won't remove any of the useless stuff in case something else in there is screwing things up.
Code:
# -*- coding: utf-8 -*-

inventory = ""

lowerHull = ('Lower Hull', "You stand in the rocking hollow space of a ship's hull. There is a doorway to the north and stairs leading up in the middle of the room.")
storageRoom = ('Storage Room', "A storage room for the crew's supplies. However, the shelves look barren right now. There is an exit to the south.")
upperHull = ('Upper Hull', 'Hull. There are stairs leading down and up.')
midDeck = ('Mid-Deck', 'You stand in the middle of the deck. There are stairs leading down into the hull. The wind blows in your hair.')
leftDeck = ('Left-Deck', 'You stand on the left side of the deck. The wind blows in your hair.')
rightDeck = ('Right-Deck', 'You stand on the left side of the deck. The wind blows in your hair.')
railing = ('Railing', "You are now able to see that you do not stand on a sea-ship. You're in a sky-ship!")

transitions = {
    lowerHull: (storageRoom, upperHull),
    storageRoom: (lowerHull,),
    upperHull: (lowerHull, midDeck),
    midDeck: (upperHull, leftDeck, rightDeck, railing),
    leftDeck: (midDeck,),
    rightDeck: (midDeck,),
    railing: (midDeck,)
}

location = lowerHull

while True:
    print location[1]
    print('You can go to these places:')

    for (i, t) in enumerate(transitions[location]):
        print i + 1, t[0]

    choice = int(raw_input('Choose one or press 0 for inventory '))
    if (choice==0):
        print ('You are holding:')
        print inventory
    else:
        location = transitions[location][choice - 1]



As you might see, I'm trying to add items (Strings, really, the items don't need to be associated with anything to actually do anything. I'll mess with defs and classes later.) to the list 'inventory'.
In case anyone is wondering, I'm using Python 2.7 on Debian Sid with IDLE Python Development Environment. I'm probably missing one simple argument I need to pass to get it to work, but that's what learning a language is about, right?
Anyways, any and all help/criticism is appreciated, so thanks in advance.

_________________
Yeah, I have nothing interesting to say.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites