shadwickman 159 Posting Pro in Training

C++ is among the top of the widely used languages for games. It retains the quick execution speed of C, and brings in much needed and required things such as objects and class inheritance (OOP). Naturally, you'd be using graphics libraries with this, such as OpenGL or DirectX. Possibly even also pre-made engines (Unreal, Crytek, etc.) if you have the hundreds to thousands of dollars.

Programming language aside, you'll also need a very strong understanding of advanced mathematics, for 3D math.

shadwickman 159 Posting Pro in Training

Annoys me. Ive learnt through working with such people on projects that a significant percentage dont work well in teams, because thier education system places a very high demand on being *the* number one through your own hard work. Gets a bit annoying when the one bloke ends up rewriting all your code on his own...

Fair enough. I haven't had those experiences that you've had. Although, I imagine some communication and coordination would also be difficult if their developers' English skills are anything like their telemarketers'...

shadwickman 159 Posting Pro in Training

You're a new programmer, yet wanting to create a game engine already? And a networked game too... wow. I assume you have a server set-up for the online transactions; or will you be converting a good computer you have sitting around at your home already? And that you'll be writing your customized server's code :P
I also assume you have a good knowledge of mathematics. Luckily, as you're going the 2D route you won't have to deal with as complex math, although you could still (try to) make a physics engine.

Tutorials and articles for:
networking and multiplayer
artificial intelligence

And here's a full walkthrough for a "simple" game engine (Enginuity).

No offense, but 95% of the people who post this kind of thing in this forum don't get anywhere; they're just hopefuls. That being said, maybe you'll be in that lucky 5% :P

shadwickman 159 Posting Pro in Training

hello.. im new from indonesia...

Hello and welcome to DaniWeb :)

This thread is an interesting choice to post your "hello" in...

shadwickman 159 Posting Pro in Training

I have the same issue. When running a wxPython program from the .py file, it uses the Windows XP Luna theme on the widgets. However, when I compile it to an .exe with py2exe, it defaults to the classic theme on the widgets (win 2000, 98, etc).

I couldn't find any information on py2exe's site about this, but to be honest, it doesn't really bother me that much. It's just a little thing.

shadwickman 159 Posting Pro in Training
shadwickman 159 Posting Pro in Training

Another solution - which I don't know if possible - might be having your main program (which opens in the background - no console itself) run two threads, one which opens up the game program and one which opens up the stat program. Then you may be able to have them communicate without the use of a file being perpetually written to and read from the HDD all the time.

shadwickman 159 Posting Pro in Training

Well technically his classes DO work for now. Although the two Character classes share so much in common that it's better structured as a base Character class, and then more specialized Serf and Peasant classes which inherit from the Character class, and add their own unique properties.

But yes, the class declarations are the general terms of what you want (hence 'template' or 'blueprint'). They aren't the individual instances...

shadwickman 159 Posting Pro in Training

pretty cool shades. aviator-type ones are all the rage now

Yeah, they seem to be. I don't own a pair myself though...

shadwickman 159 Posting Pro in Training

Would that work? Wouldn't it just open one program in the DOS console, wait until it ends, then run the second?

shadwickman 159 Posting Pro in Training

You were on the right track. Find the 'del' part, then include backwards until you encounter an underscore; this allows for if the number was single, double, triple, quadruple, etc digits long.

filename = '/grups.google.com/grup/cmp.lng.pythn/browse_thread/thread/8_ee63e_17del_0c12d'
end = filename.find('del')
# reverse-find the first underscore in the filename
# from the 0-index to the end we just calculated.
# we add one because we want our start to be one
# past the underscore.
start = filename.rfind('_', filename[:end]) + 1
number = filename[start:end]
shadwickman 159 Posting Pro in Training

Yes, but are you going to make the user open the second program when they run the game?
You can't open a new console window through your main Python script.

shadwickman 159 Posting Pro in Training

Your code will still be creating instances of both character classes. Like I said previously, you need conditional statements to handle whether something should be executed, or something else should in its place. What you're currently doing is creating an instance of Character_1, and then afterwards, creating an instance of Character_2.

Also, you were trying to initiate the player classes from within the main menu's WhichCharacter() function. This is wrong because the variable you store it in is local only to that scope and can't be accessed outside of that method. It's better to return the input to handle in the main scope of the program than try to mess with global variables.

I've fixed your code for you:

# We define all our class 'templates' up here.
# Remember, these aren't executed yet. They only
# are once we call on them during our program.
# These are just so the interpreter knows what a
# MainMenu class entails, etc.

class MainMenu():
    def __init__(self):
        print 'Welcome to Dark Forest!'
    def WhichCharacter(self):
        print 'Choose a Character to play'
        print '1)serf'
        print '2)peasant'
        options = ['serf', 'peasant']

        while True:
            # FIXED THIS:
            choice = raw_input('Which Character?(i.e serf):').lower()
            # If the input is in the list 'options':
            if choice in options:
                # return the input so that the global variable
                # 'choice' (from mm.WhichCharacter()) stores it.
                return choice
            else:
                print 'Invalid choice'
    
class Character_1:
    def __init__(self,char):
        self.char = char
        self.gold = 150
        self.level = 1
        self.attack = 3
        self.defend …
shadwickman 159 Posting Pro in Training

... Super Moderator badge?

can i have it?

You have my vote. I believe the forums would be filled with a lot less of the "i has homework give me code plz" posts.

jephthah commented: building an army, one comrade at a time +14
shadwickman 159 Posting Pro in Training

And before anybody makes a comment about either the shades or the colourful bedsheets in the background, they are my ex girlfriend's, hence the feminine tinge to them.

shadwickman 159 Posting Pro in Training

Well now... I think I'll just drop this and slowly back away, avoiding all eye-contact in the process...

shadwickman 159 Posting Pro in Training

That is why i respect a blonde cute female c++ developer too much. She could have taken advantage of her beauty instead of ... <snip>

Let's please not let this thread steer in the creepy direction too. That whole post was completely unnecessary and I really didn't need to read more of that drivel.

That being said, I'm not surprised that the whole development team is Indian; they have a MASSIVE population. And hey, there's nothing wrong with so many of them taking these tech jobs. Good for them for showing up any citizens in the country that the company is based out of.

shadwickman 159 Posting Pro in Training

Sorry, I wasn't fully clear on what I meant by declaring them at the top. Think of the whole of each class block being a blueprint. So before you can make the thing, you need the blueprint first, i.e. you put the blocks of class declarations at the top, then below them (later in the script), you can make instances of them. Here's a template:

# put these CLASS blocks at the top
class Character_1(object):
    def __init__(self, char):
        self.char = char

class Character_2(object):
    def __init__(self, char):
        self.char = char

# now, we can make instances of them
inst1 = Character_1("serf")
inst2 = Character_2("peasant")

That's a rough structure. Below is code that WILL NOT work:

# no good!
inst = MyClass("Frank")

class MyClass(object):
    def __init__(self, name):
        self.name = name

The second code won't work because you told the interpreter (the thing 'reading' the code) to make an instance of MyClass BEFORE you gave it the blueprint for MyClass.

Your lines

C1 = Character_1
C2 = Character_2

are unnecessary because all that does is allow you to call the Character_1 class by using C1() now, as well as Character_1() .
Be careful! The parenthesis at the end make a call to that class, i.e. create an instance of it. If you don't have the parenthesis, you're just accessing the class object in memory, not calling it.

shadwickman 159 Posting Pro in Training

What does your main package __init__ file look like? It could be that you're doing something like from subpackage1 import * , in which case, the module subpackage1 wouldn't actually be defined. You'd just be dumping everything from its namespace into the main one. Of course, this is just my guess at what's going on in your package/__init__.py file.

Also, you could always use the sys module and inside the ClassA.py, do something like:

import sys
sys.path.append("..")  # look inside parent directory (subpackage1/)
from baseclass import BaseClass  # it will now find this in the parent dir

class ClassA(BaseClass):
    pass
shadwickman 159 Posting Pro in Training

Ah, a number of errors!

1. You need to understand that when you write a class, it won't get executed UNTIL you create an instance of it, i.e. var = myClass() . So you can define all your classes at the top of your script, and the order doesn't matter. What matters is when you create instances of them.

2. Please don't use self outside of the class - it makes your code really confusing. WITHIN the class, self refers to itself, but outside of the class, give it a different name that refers to the initialized instance you have created, i.e.:

class MyClass(object):
    def __init__(self, name):
        self.name = name
    def sayHi(self):
        # notice that when referring to anything in this class
        # from WITHIN itself, we use the 'self' name.
        print "Hello, my name is", self.name

# only when we call an instance of this class is its code executed
inst = MyClass("Frank")
# when referring to parts of the class from OUTSIDE
# of its declaration, we use the variable name we assigned it
# to. Preferrably not 'self' as that gets confusing.
print "The class' name is", inst.name
inst.sayHi()

3. Like I said, the script executes downwards. What you have in yours is:
- you make the main menu
- you get the choice
- you make a Character_1 class instance
- you make a Character_2 class instance
Declare all your classes at the top of your script (to …

shadwickman 159 Posting Pro in Training

With a Zymic account, you could just change whatever folder you're using for storage so that the permissions don't allow public reading/executing.

I use my account with them a lot for storage, but I also do run a simple photography page off it it too.

This differs from FileFront though because this isn't just file hosting - it's a personal website essentially.

shadwickman 159 Posting Pro in Training

if choice in options == 1 is redundant; choice in options already returns a boolean (True or False) if the value for choice is in the list options.

You need to change your options list to include the things that you want as valid input, like I did ('serf', 'baron', etc).

Also, when you check if choice is in options, convert choice to lower-case first so that if the user types "SERF" or "SeRf", etc, it'll be checked as "serf". (Just make sure that your options list has the valid inputs in lower-case too).

So if you make these changes (which makes your code like that code that I had posted), it should break out of the loop (and return the choice) once something valid is entered.

shadwickman 159 Posting Pro in Training

Thanks! Just note that with the above code you'd still need to take into account incorrect input, like a user entering an invalid option for the class, etc. You could fix the MainMenu's getWhichClass method to handle this accordingly:

class MainMenu(object):
    def __init__(self):
        # do your stuff here
    def askWhichClass(self):
        # available options in a list
        options = ['serf', 'baron']
        while True:
            choice = raw_input("Which class?  ")
            # check if the choice is in the options list
            # (convert to all lowercase first to allow for case-insensitive input)

            # if so, return the choice (which also breaks the while loop)
            if choice.lower() in options:
                return choice
           # if not, don't break out of the loop,
           # so that it regathers input until it gets a valid choice
           else:
                print 'Invalid choice!'
shadwickman 159 Posting Pro in Training

So if you're just looking for storage, you can get a free account with Zymic.com (something like mysitename.vndv.com) which has 6GB of storage and an absurd amount of bandwidth too.

shadwickman 159 Posting Pro in Training

Remember that the script executes downwards; it doesn't all happen at once. Things like raw_input also stall until input is given, then the script continues. So this is fairly easy to do; here's an outline of what you'll want:

class MainMenu(object):
    def __init__(self):
        # do your stuff here
    def askWhichClass(self):
        choice = raw_input("Which class?  ")
        return choice

# define your player classes here...

mm = MainMenu()
choice = mm.askWhichClass()
if choice == 'serf':
    player = PlayerSerf()
elif choice == 'baron':
    player = PlayerBaron()
# etc...

This first initializes an instance MainMenu class (as mm). Then we call its method for getting the user's choice (via the raw_input statement) and then we check it with if statements to make player an instance of the appropriate class.
Hope this clears up your confusion!

shadwickman 159 Posting Pro in Training

Are you talking about having your own host for this or some sort of community-based site?

shadwickman 159 Posting Pro in Training

Oh! How could I miss it! You're using things like player.gold and player.level , etc. That's wrong, because player is undefined within that scope. When you're changing a class' properties and such from within itself, you use self. Your Level_Up function should read:

def Level_Up(self, x):
        self.level += 1
        self.gold += 125
        self.attack += 2
        self.defend += 1
        if self.level >= 1:
            print 'Level:',
            print self.level
            print 'Gold:',
            print self.gold
            print 'Attack',
            print self.attack
            print 'Defend:',
            print self.defend

That's what has been messing it up :P

shadwickman 159 Posting Pro in Training

I see an error. Why do you have if player.Level_Up >= 1 ? Shouldn't that be if player.level >= 1 ? The value of player.Level_Up (which is the function) will be something like <bound method Character_1.Level_Up of <__main__.Character_1 object at 0x00D89110>> And you can also simplify those additions you make by using the += operator. So instead of player.gold = player.gold + 125 you can write player.gold += 125 . Similar operators are:
-=
*=
/=

shadwickman 159 Posting Pro in Training

Well the simplest solution is just to use the style flag wx.TE_PASSWORD when you create the TextCtrl for the password. That automatically makes the output asterisks.

shadwickman 159 Posting Pro in Training

Yep, and there you have the start of it! Now you can just add the methods you want, like maybe a doAttack function,

from random import randint

class Character_1:
    def __init__(self,char):
        self.char = char
        self.gold = 0
        self.level = 1
        self.attack = 7
    
    def doAttack(self):
        # get a damage amount ranging from half
        # the attack value, up to the attack value
        # note that 'minimum' is integer division, so it'll truncate,
        # i.e. 7 / 2 = 3  (it cuts off the decimal part)
        minimum = self.attack / 2
        maximum = self.attack
        damage = randint(minimum, maximum)
        return damage

Note that minimum is integer division, so it's essentially rounding down by cutting off the decimal point. And the randint function chooses a random integer in the range from minimum up to and including the maximum.

EDIT:
In response to you wanting to add 200 gold to the player upon initialization, then just change the self.gold = 0 inside __init__ to self.gold = 200 .

shadwickman 159 Posting Pro in Training

The __init__ function is called when you create a new instance of that class. So when zac said player = NewPlayer('Paul') , the __init__ function of the NewPlayer class was called, and the instance of that class was stored by the name player.

If you want to call methods in the class, then you can do so by simple using that dot notation like you did for the variables: player.someFunction() . Note however, that the functions contained in the class must be defined with self as the first parameter, but when you make calls to them, self is assigned automatically based on the object instance you're making the call from.

class NewPlayer:
    def __init__(self,name):
        self.name = name
        self.gold = 0
    def sayHi(self):
        print 'hello!'

player = NewPlayer('Paul')
player.sayHi()

Note that the first argument for sayHi is self? But when we call it via player.sayHi() , we don't need to pass anything because self is given by player, the variable whose method we're calling. And the same goes for calls to those functions from within a class; if we wanted to call sayHi from within the __init__ function, we'd use self.sayHi() .

Hope that helped a bit :P

shadwickman 159 Posting Pro in Training

Wow. He had to tase a pig? What a man...
I guess they'll be needing those tasers for the estimated 100,000 Burmese Pythons that are on the loose in Florida though.

shadwickman 159 Posting Pro in Training

re.split breaks the string in the specified pattern, removing the parts which caused the split. There is a much simpler solution to this problem though. Just iterate the string by splitting it at each space and compare each word to a list of words you're watching for. You don't need regular expressions for this problem:

def myFunc(s):
    # break the string into a list (at each space)
    words = s.split(' ')
    # put the words we are watching for into a list
    watched = ['this', 'a']

    # loop our words and check each one
    # and add the result to our result list
    result = []
    for w in words:
        # if the word is in the watched list
        # add the carets to each side
        if w in watched:
            w = '<' + w + '>'
        # add the word to the result list
        result.append(w)

    # join our result into a string with spaces in between
    result = ' '.join(result)
    return result

My result:

>>> s = 'Hello this is a test'
>>> myFunc(s)
'Hello <this> is <a> test'

A much simpler and cleaner solution, I think :P

shadwickman 159 Posting Pro in Training

On Windows, I just use Notepad++ as an editor and then I run scripts from the console. On Ubuntu, I use gedit to write and then again, I run the scripts from the console. I don't need all those fancy schmancy IDEs :P

shadwickman 159 Posting Pro in Training

Like zachabesh said, you should take a look at the shutil module for more file operation functions. And copytree may be of particular interest to you too :P

shadwickman 159 Posting Pro in Training

This is exactly what I was saying. You put 5 - that's an integer. I said that the code I wrote required a list. Please read a book on Python because if you had a good basic knowledge, you would understand that x needs to be a list because of the notation x[-1] . That square bracket notation is for iterable objects, and it returns the specified index in the list (in this case, -1, the last index from the end).

The reason I was using a list in the first place was because you said that you wanted to track the history, which is what a list would be perfect for. So, for this to work, you need to have the variable you pass to the function as a list, like I did in my example with gold = [100] . Notice the square brackets around 100? That means that 'gold' is a list, and it has one index at the moment, with a value of 100.

You could modify your goldKeeper function to take an integer, but then you'd have to pass it the last index from the 'gold' list, rather than the list itself. Either way works...

shadwickman 159 Posting Pro in Training

What you re-posted gives me no errors. This is assuming that you are running it all by itself without incorporating it into whatever script you already had. Save the code I posted into a .py file all by itself, then run that. You'll see that you won't get an error.

The only reason why it should mess up is if you tried to incorporate it into your pre-existing script and forgot to change something else somewhere. Please post the exact traceback error it's giving you.

EDIT:
@woooe,
I was assuming that he'd be setting 'gold' to some initial value, and that 'a' would not always be set to 200 (I thought he put it there for testing purposes). Otherwise, there really seems to be no point to this function...

shadwickman 159 Posting Pro in Training

So I take it that you fixed the TypeError you were getting when you didn't have your gold variable as a list?

shadwickman 159 Posting Pro in Training

jice is right. You're telling it to start at 0 and end at 13, but your step is -1, so it won't work. I think you're a little confused; the -1 does not 'reverse' the operation. It sets the amount it steps by each time...

So if I set it to 2, it would increment over the string by 2 indices each time, like this:

>>> a = 'Hello World!'
>>> a[0:13:2]
'HloWrd'

So a negative step simply means it'll iterate backwards by that number. You still need to adjust your range's start and end indices accordingly though.

shadwickman 159 Posting Pro in Training

Well your code confuses me. The first instance of j is in a conditional statement comparing it to the number 7. I don't see it even initialized before that. And the same goes for a. Oh, and Iteration - what's the value of that?

Maybe post code explaining what those variables are and what they're for, or at least all 3 for loops that you're using as you said you had trouble with the third, but I only see two posted above.

EDIT:
I just spotted your ++j line. That doesn't do anything as far as I know. You'll need to change it to j += 1 . See below:

>>> j = 0
>>> ++j
0
>>> # j is still zero...
>>> j += 1
>>> j
1
>>> # but += 1 worked
shadwickman 159 Posting Pro in Training

Ah, it means that you are passing an integer to your function. Do you see in my code that I declared gold as a list? A list is a different variable than an integer. (Here's a bit of documentation on it.) So what I did is use a list which has integers in it as the indices. So x[-1] is the last item in the list, i.e. the most current value. You need to declare your gold variable that you pass to the goldKeeper function as a list, and then to get its current value, you need to access the last item in it by using that square-bracket notation.

It sounds like you really need to read up on the basics of Python and/or programming in general. Here's a very good, free, online Python book.

>> "...or a different toolkit?"
No, this has to do with core aspects of the language. It's like that math question you asked about wxPython. Calculations are still in Python - they aren't changed by a toolkit, unless the toolkit you're talking about introduces new mathematical possibilities, i.e. the module numpy. In this case, you're using core data structures of Python so they're the same (99.9% of the time) with whatever extra modules you're using.

shadwickman 159 Posting Pro in Training

Keep the gold amount as a list:

def goldKeeper(x):
    a = 200

    # if 'x' contains any indices
    if x:
        if x[-1] <= a:
            # store new 'x' value
            x.append(a)
        elif x[-1] >= a:
            print a + x,

    # if 'x' is a blank list
    else:
        print a+x,

gold = [100]
goldKeeper(gold)
"""my result for gold ->
[100, 200]
"""

This shows that the new value for 'gold' is added onto the end of the list so that you have a sort of history of past values.

Though I'm still thoroughly confused about why you have the conditional statements. You listed print a+x, for both of them... so what were you trying to do? I just assumed that you'd store 'a' as the new value of 'x' if 'a' is more than the current 'x' value.

Hope I helped :)

shadwickman 159 Posting Pro in Training

I get this error if I run a wxPython program more than one time from within IDLE. For some reason, IDLE buggers it up, which is why I don't develop with it. If you close IDLE and re-open your script and run it once, it should work the first time, and then give you this error on each subsequent call.
Just write your code in a better editor and run it from the command line to test it. That way you can avoid IDLE :P

shadwickman 159 Posting Pro in Training

There should be some sort of static bitmap within Tkinter that you can place on these screens (if they are, in fact, Tkinter windows).

shadwickman 159 Posting Pro in Training

From the py2exe site:
"py2exe does not currently (as of 0.6.5) work out of the box if some of your program's dependencies are in .egg form. "

So, here's some py2exe documentation about including .egg files in the .exe. I hope this will help you out :)

shadwickman 159 Posting Pro in Training

Open the .egg in Notepad and see what sort of data in contains... I've personally never used mechanize, but then again I've never encountered a module that ran with only an egg file. It could be a common thing that I just have had no experience with though :P

shadwickman 159 Posting Pro in Training

Is there a file in the C:\Python25\Lib\site-packages folder named mechanize.pth or a folder named mechanize in that directory? There should be, and the data in mechanize.pth should simply say "mechanize" (without the quotes).

shadwickman 159 Posting Pro in Training

Can you please post a smart question? You included no details about this "python application output" or anything about your program as it is. Then maybe I'll help.

shadwickman 159 Posting Pro in Training

The Europeans did that to themselves, Microsoft had nothing to do with it.

Actually I think Microsoft did have a large something to do with that. Hence the whole issue in the first place.

shadwickman 159 Posting Pro in Training

You can execute it using the os module. In DOS or GNU/Linux, in the command line you can type python code.py to execute a file. So you can try this:

import os
os.system("python othercode.py")

The one problem would be if the user does not have "python" registered as a recognized command. Below is the universal solution which locates the user's python executable and uses a system call to that with its absolute path:

import os
import sys
pyexe = sys.executable  # something like "C:\Python25\python.exe"
os.system('%s othercode.py' % pyexe)

This should be cross-platform compatible. Hope that helped!