General Development

Python Help Thread – Xian_Lee

Xian_Lee

Member

Posts: 345
From:
Registered: 03-15-2006
Hey everyone, I was trying to find a thread that offered help with Python, but I had little luck, so I created one.

Today, I'm having difficulty figuring out how some of the variable types work in Python. So far as I can tell, it's (Python) extremely type independent. Specifically, I just throw a name into the code and assign a value. Well, my current trouble is that I want to work with booleans. When coding, I really prefer a basic true/false over working with integers when possible. I know that a simple Google search would probably help me with this, but I wanted to see what kind of responses I would get here.

Thanks for the help! Right now, I'm working on a simple Asteroids-style game, and I thought it worth pointing out that I haven't been (entirely) slacking with game development (though I did give a lot of my available time to Final Fantasy XII this last week).

------------------
Information on my projects
My game industry/theology blog
My Original Music

Lazarus

Member

Posts: 1668
From: USA
Registered: 06-06-2006
If I recall, they added a boolean type in Python 2.3, and the constants True and False.

If you do

>>> bool(1)
the interpreter returns True, and likewise with bool(0).

HTH.

Xian_Lee

Member

Posts: 345
From:
Registered: 03-15-2006
HTH?

Thanks for the info. I'm not sure that that helps in my case.

Also, I'm fairly new to using the PyGame toolset as well. I'm using something like the following for detecting input (slightly modified from a tutorial I found), but I want to figure out how to respond to key release instead of responding only to key press.

for event in pygame.event.get():
if not hasattr(event, 'key'): continue
down = event.type == KEYDOWN
if event.key == K_RIGHT: car.k_right = down * -5
elif event.key == K_LEFT: car.k_left = down * 5
elif event.key == K_LSHIFT:
car.k_up = down * 10
car.isBoosting = 'true'
elif event.key == K_UP: car.k_up = down * 1
elif event.key == K_DOWN: car.k_down = down * -1
elif event.key == K_ESCAPE: sys.exit(0)

I added "up = event.type == KEYUP" with the hope of being able to get something to work, but it seems that "event.key" only works when a key is pressed, and doesn't pay attention to when a key is released.

Any advice would be greatly appreciated!

EDIT: I had a little bit of insight as to how this system of movement was working, and I've figured it out. I now have a sprite soaring around on screen (like Asteroids), and have included a boost function that gives a fast start and double the speed, but punishes the player with a half a second stall at the end of the boost to keep the player from going right away. The boost is presently unlimited.

------------------
Information on my projects
My game industry/theology blog
My Original Music

[This message has been edited by Xian_Lee (edited March 23, 2007).]

CPUFreak91

Member

Posts: 2337
From:
Registered: 02-01-2005
quote:
Originally posted by Xian_Lee:
Well, my current trouble is that I want to work with booleans. When coding, I really prefer a basic true/false over working with integers when possible.

Not sure what you mean.
Do you mean something like this?

a = True
b = False
c = None
if a != b:
print "'taint equal"
if c == None:
print "Nothing to see here."

------------------
All Your Base Are Belong To Us!!! chown -r us ./base
"After three days without programming, life becomes meaningless.'' -- Tao of Programming Book 2

"Oh, bother," said the Borg. "We've assimilated Pooh."

"Socialism works great... if there are no people involved." -- Pastor David Ginter, Union Church of Guatemala.

My Programming and Hacker/Geek related Blog

Xian_Lee

Member

Posts: 345
From:
Registered: 03-15-2006
That's more or less what I was hinting at. In C++, for example, I would do something like this. (Sorry about not being able to do your fancy code block trick.)

// Beginning of app/character class.
bool isAlive = false; // As a general rule, I initiate my variables to null/false.

// Instantiating a character object.
isAlive = true; // I then set them when I am ready to use them.

// Game loop.
while(isAlive) // That could also be written as while(isAlive == true)
{
// Do everything.
}

Does that make a little more sense?

Anyway, I've made a bit of progress in my Asteroid-like. You can read about it in the weekly updates thread and/or my work log on Google (link is in the signature).

Thanks for the help.

------------------
Information on my projects
My game industry/theology blog
My Original Music

[This message has been edited by Xian_Lee (edited March 24, 2007).]

evdude

Member

Posts: 135
From: Earth Orbit
Registered: 03-14-2007
How about:

isalive = True #the T in True is caps in Python

while isalive: #or while isalive == True
****do what ever

is that what you ment?

and for the input thing you could do:

if event.key == K_UP:
****what ever
else:
****do the thing you wanted to do

note: the *s are represent spaces or one tab

------------------
"trust in the lord with all your heart and lean not on your own understanding, in all your way's, acknowledge him and he will direct your path" proverbs 3:5-6

[This message has been edited by evdude (edited March 25, 2007).]

Xian_Lee

Member

Posts: 345
From:
Registered: 03-15-2006
Awesome. Thanks for that. "True" and "False" are the keywords used for boolean? I'm just so used to everything being lowercase, so I didn't think to try that. Thanks!

------------------
Portal with information on my programming projects and links to my other work

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
yeah you can also do TRUE and FALSE I think. don't remember.

shout at me if I'm wrong, CPU.

------------------
that post was really cool ^
|
[|=D) <---|| me

evdude

Member

Posts: 135
From: Earth Orbit
Registered: 03-14-2007
Ha Ha! Wrong!!

------------------
"trust in the lord with all your heart and lean not on your own understanding, in all your way's, acknowledge him and he will direct your path" proverbs 3:5-6

CPUFreak91

Member

Posts: 2337
From:
Registered: 02-01-2005
quote:
Originally posted by buddboy:
yeah you can also do TRUE and FALSE I think. don't remember.

shout at me if I'm wrong, CPU.



Me and Python are shouting at you because it's not legal.
x = TRUE
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'TRUE' is not defined

------------------
All Your Base Are Belong To Us!!! chown -r us ./base
"After three days without programming, life becomes meaningless.'' -- Tao of Programming Book 2

"Oh, bother," said the Borg. "We've assimilated Pooh."

"Socialism works great... if there are no people involved." -- Pastor David Ginter, Union Church of Guatemala.

My Programming and Hacker/Geek related Blog

Xian_Lee

Member

Posts: 345
From:
Registered: 03-15-2006
I'm confused now. I should probably just go test these things for myself, but are True and False (with that capitalization) legitimate boolean values? I knew that true and false (written as such) are not, and, as CPU has just pointed out, TRUE and FALSE are not either.

Anyway, I didn't mean for this thread to be a "help me" thread, but a "come here for help" thread. As such, I wanted anybody to be able to come in and ask for help should they get hung up in Python.

------------------
Portal with information on my programming projects and links to my other work

Lazarus

Member

Posts: 1668
From: USA
Registered: 06-06-2006
True and False(as spelled that way) are the constants. It only takes three seconds to check out in the python interpreter.
buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
well in my defense I did ask you to tell me if I was wrong, so I was anticipating my wrongness. haha.

hey XL that asteroids thing looks cool. you mentioned a tutorial. what tutorial is it? I've been looking for a good Pygame tutorial.

------------------
that post was really cool ^
|
[|=D) <---|| me

CPUFreak91

Member

Posts: 2337
From:
Registered: 02-01-2005
quote:
Originally posted by Xian_Lee:
I'm confused now. I should probably just go test these things for myself, but are True and False (with that capitalization) legitimate boolean values? I knew that true and false (written as such) are not, and, as CPU has just pointed out, TRUE and FALSE are not either.


To settle any doubts, go to: http://www.python.org/doc/2.4.2/lib/node31.html and http://www.python.org/doc/2.4.2/lib/types.html

quote:
Originally posted by buddboy:
I've been looking for a good Pygame tutorial.


These tutorials really helped me: http://rene.f0o.com/mywiki/PythonGameProgramming

http://www.pygame.org/docs/tut/newbieguide.html

Awaretek also has over 300 links to various Python tutorials: www.awaretek.com/tutorials.html covering everything from console programming, gui programming, web programming, to multimedia stuff.

------------------
All Your Base Are Belong To Us!!! chown -r us ./base
"After three days without programming, life becomes meaningless.'' -- Tao of Programming Book 2

"Oh, bother," said the Borg. "We've assimilated Pooh."

"Socialism works great... if there are no people involved." -- Pastor David Ginter, Union Church of Guatemala.

My Programming and Hacker/Geek related Blog

[This message has been edited by CPUFreak91 (edited March 26, 2007).]

Xian_Lee

Member

Posts: 345
From:
Registered: 03-15-2006
Hey Buddboy,

The tutorial I was referring to was written by Richard Jones. It was one of the first links on the Tutorials section of the PyGame website. The title of the tutorial is Rapid Game Development. You can get it here: http://richard.cgpublisher.com/product/pub.84/prod.11

I should stop feigning ignorant.

------------------
Portal with information on my programming projects and links to my other work

evdude

Member

Posts: 135
From: Earth Orbit
Registered: 03-14-2007
quote:
Originally posted by Xian_Lee:
Anyway, I didn't mean for this thread to be a "help me" thread, but a "come here for help" thread. As such, I wanted anybody to be able to come in and ask for help should they get hung up in Python.

All Right! does any one here know of a good 3D module for Python?
it needs to come in a installer.

------------------
"trust in the lord with all your heart and lean not on your own understanding, in all your way's, acknowledge him and he will direct your path" proverbs 3:5-6

[This message has been edited by evdude (edited March 26, 2007).]

HanClinto

Administrator

Posts: 1828
From: Indiana
Registered: 10-11-2004
PyOgre has an installer, as does Panda3d. Steveth45 will be working on a binding for Irrlicht, and he actually just posted about it over in the weekly updates thread.

Hope that helps!

--clint

evdude

Member

Posts: 135
From: Earth Orbit
Registered: 03-14-2007
Thanks! I'm going to try panda3D. I'm going to download it over night, since it's going to take 5+ hour to download

------------------
"trust in the lord with all your heart and lean not on your own understanding, in all your way's, acknowledge him and he will direct your path" proverbs 3:5-6

[This message has been edited by evdude (edited March 26, 2007).]

D-SIPL

Moderator

Posts: 1345
From: Maesteg, Wales
Registered: 07-21-2001
I used Panda3D a while ago. It was to prototype an Othello game that used the MiniMax and AlphaBeta algorithms. I think Panda3D was worked on and used by Disney, possibly for an MMORPG too!? don't quote me on that though

------------------
"One World. One Web. One Program." -Microsoft promotional advertisement
"Ein Volk, ein Reich, ein Fuhrer!" -Adolf Hitler
"I believe in freedom... not freedom like America, freedom like a shopping cart"

HanClinto

Administrator

Posts: 1828
From: Indiana
Registered: 10-11-2004
quote:
Originally posted by D-SIPL:
I think Panda3D was worked on and used by Disney, possibly for an MMORPG too!? don't quote me on that though

Oops, just quoted you. It was necessary for context.

But at least you can rest assured that you are correct -- Disney put a lot of work into Panda3D as the rendering engine for their first MMORPG called Toontown Online. It's a decently fun game, but it's a bit of a grind at times. They made things much more casual with their second MMORPG, called Virtual Magic Kingdom.

evdude

Member

Posts: 135
From: Earth Orbit
Registered: 03-14-2007
* 349684

yes! finally, a 3D thing that works! thanks hanclinto!

------------------
"trust in the lord with all your heart and lean not on your own understanding, in all your way's, acknowledge him and he will direct your path" proverbs 3:5-6

evdude

Member

Posts: 135
From: Earth Orbit
Registered: 03-14-2007
Aaack!
well, panda works fine for our family's computer, but directx stuff doesn't work on my laptop. is there an installer for some openGL thing?

------------------
"trust in the lord with all your heart and lean not on your own understanding, in all your way's, acknowledge him and he will direct your path" proverbs 3:5-6

Lazarus

Member

Posts: 1668
From: USA
Registered: 06-06-2006
Depends on your 3D card - you can download drivers for ati cards and such.
evdude

Member

Posts: 135
From: Earth Orbit
Registered: 03-14-2007
how?

------------------
"trust in the lord with all your heart and lean not on your own understanding, in all your way's, acknowledge him and he will direct your path" proverbs 3:5-6

Lazarus

Member

Posts: 1668
From: USA
Registered: 06-06-2006
Start here: http://ati.de/support/driver.html
evdude

Member

Posts: 135
From: Earth Orbit
Registered: 03-14-2007
Hmmm.....
That doesnt work, it doesnt have my driver.
thanks any way.

------------------
"trust in the lord with all your heart and lean not on your own understanding, in all your way's, acknowledge him and he will direct your path" proverbs 3:5-6

[This message has been edited by evdude (edited April 09, 2007).]

evdude

Member

Posts: 135
From: Earth Orbit
Registered: 03-14-2007
Ok, I got panda3D working. Had to change hardware to software in the config file.

------------------
"trust in the lord with all your heart and lean not on your own understanding, in all your way's, acknowledge him and he will direct your path" proverbs 3:5-6

CPUFreak91

Member

Posts: 2337
From:
Registered: 02-01-2005
quote:
Originally posted by evdude:
Ok, I got panda3D working. Had to change hardware to software in the config file.



Nice. I'm trying to get Panda3D to work too, except my problem is a dependency conflict which I will work out soonish.

------------------
All Your Base Are Belong To Us!!! chown -r us ./base
"After three days without programming, life becomes meaningless.'' -- Tao of Programming Book 2

"Oh, bother," said the Borg. "We've assimilated Pooh."

"Socialism works great... if there are no people involved." -- Pastor David Ginter, Union Church of Guatemala.

My Programming and Hacker/Geek related Blog

D-SIPL

Moderator

Posts: 1345
From: Maesteg, Wales
Registered: 07-21-2001
It was a pain to get working on Slackware, I did post my solution in the forum.

------------------
"One World. One Web. One Program." -Microsoft promotional advertisement
"Ein Volk, ein Reich, ein Fuhrer!" -Adolf Hitler
"I believe in freedom... not freedom like America, freedom like a shopping cart"