Need some simple coding help

Steven Bethard steven.bethard at gmail.com
Tue Mar 1 23:51:40 CET 2005


mx2k wrote:
> Hello @ all,
> 
> we have written a small program (code below) for our own
> in-developement rpg system, which is getting values for 4
> RPG-Characters and doing some calculations with it.
> 
> now we're trying hard to find out how to get it working with 'n'
> Characters, so you will be asked to enter a number at the beginning,
> asking you how many characters you want.
> 
> anyone out there who could help us?

Why don't you try describing what it is you're trying to do in some more 
detail -- your code is fairly unreadable.

I gather you want to do something like:

py> class Character(object):
...     def __init__(self, name, initiative, reaction_time):
...         self.name = name
...         self.initiative = initiative
...         self.reaction_time = reaction_time
...     def __repr__(self):
...         return 'Character(%r, %r, %r)' % (
...             self.name, self.initiative, self.reaction_time)
...
py> def get_char():
...     return Character(raw_input("Char 1 Name: "),
...                      int(raw_input("Char 1 Initiative: ")),
...                      int(raw_input("Char 1 Reaction Time: ")))
...
py> n_chars = int(raw_input('Number of Characters: '))
[...I type '2'...]
py> characters = [get_char() for _ in xrange(n_chars)]
[...I type 'Steve', '3', '2', etc....]
py> characters
[Character('Steve', 3, 2), Character('mx2k', 5, 1)]

But it's not clear to me what it is you want done with the characters. 
It looks like you're maybe trying to go through rounds of combat, 
sorting characters by initiative...?  What exactly is the process you're 
attempting to follow?

If you try to describe the problem in words, you'll probably get more 
help.  (Code is generally good too, but if it's not clear what you're 
trying to do with the code, no one will be able to make use of it.)

STeVe



More information about the Python-list mailing list