Python - A quick look

Post your own tutorials, guides and demos.

Post » Wed Jan 06, 2010 12:17 am

[quote="David":nfi8wwdi]And now a cool chain/snake example for python

http://dl.dropbox.com/u/939828/Python%20Chain.cap

Tomorrow I will explain how it works.[/quote:nfi8wwdi]

Welp, I guess I do need to install Python to run scripts after all...?

[code:nfi8wwdi]An error occured in python, but construct is unable to obtain any error information without StringIO.pyc[/code:nfi8wwdi]

Um, also "occurred" is misspelled in that error, and Python and Construct should be capitalized. There's errors in your error so you can error while you error :P
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Wed Jan 06, 2010 9:28 am

that is very awesome indeed davo
Spriter Dev
B
87
S
21
G
12
Posts: 3,240
Reputation: 16,461

Post » Wed Jan 06, 2010 9:29 am

Atleast you don't get error from error after having error which has errors? Anyways it's cool example and tbh I think I really need to start looking into Python the code is just so short and clean compared to same thing done in events (atleast for me xD)
B
11
S
3
G
4
Posts: 622
Reputation: 3,186

Post » Fri Jan 08, 2010 7:53 am

Any way to use Sprite[1] with regular events?
Its sooo much easier to pick from multiple instances... when you have them indexed like that.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Fri Jan 08, 2010 9:59 pm

Okay lucid convinced me to install Python and give learning it another go. After reading Davo's post I was able to move just three instances in the snake .cap with a loop I made:

[code:28n06wce]for n in [8, 12, 16]:
Body[n].X += 1[/code:28n06wce]

It only took me four tries to get it right without errors! A proud boy am I! :mrgreen:

I still don't see how this is going to be useful to me personally yet since I don't relly make anything all that complex, but I'm willing to read more Python tuts if anyone wants to make them.

PS that snake thing is pretty neat, David.
Moderator
B
5
S
2
G
6
Posts: 4,348
Reputation: 10,971

Post » Fri Jan 08, 2010 10:09 pm

Darn, I've been learning Ruby. One of these days I should give Python a second glance... I'm kinda busy on my Ruby project, though.

Which begs a question - how does Construct implement Python? Would it be possible to support another language, such as Ruby or LUA?
B
62
S
21
G
12
Posts: 1,910
Reputation: 13,155

Post » Sat Jan 09, 2010 2:09 am

Looks like you might be able to make a joystick controller via pygame.

[code:2tq20idp]import pygame
pygame.init()
pygame.joystick.init()
count = pygame.joystick.get_count()

if count > 0:
j = pygame.joystick.Joystick(0)
j.init()
num_axes = j.get_numaxes()
num_buttons = j.get_numbuttons()
last_axes = [j.get_axis(i) for i in xrange(num_axes)]
Text.text = num_buttons[/code:2tq20idp]
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

Post » Tue Jan 12, 2010 2:29 am

[quote="newt":18ersfhj]Looks like you might be able to make a joystick controller via pygame.

[code:18ersfhj]import pygame
pygame.init()
pygame.joystick.init()
count = pygame.joystick.get_count()

if count > 0:
j = pygame.joystick.Joystick(0)
j.init()
num_axes = j.get_numaxes()
num_buttons = j.get_numbuttons()
last_axes = [j.get_axis(i) for i in xrange(num_axes)]
Text.text = num_buttons[/code:18ersfhj][/quote:18ersfhj]

This. Is so awesome. I never thought of it before.
B
3
S
2
G
4
Posts: 1,445
Reputation: 4,665

Post » Wed Jan 13, 2010 3:41 pm

[code:2cmpbzwh]#!/usr/bin/env python
background_image_filename = 'arrow.png'
mouse_image_filename = 'redcube.png'
import pygame
from pygame.locals import *
from sys import exit
pygame.init()
screen = pygame.display.set_mode((640, 480), 0, 32)
pygame.display.set_caption("Hello, World!")
background = pygame.image.load(background_image_filename).convert()
mouse_cursor = pygame.image.load(mouse_image_filename).convert_alpha()
while True:
for event in pygame.event.get():
if event.type == QUIT:
exit()
screen.blit(background, (0,0))
x, y = pygame.mouse.get_pos()
x-= mouse_cursor.get_width() / 2
y-= mouse_cursor.get_height() / 2
screen.blit(mouse_cursor, (x, y))

pygame.display.update()[/code:2cmpbzwh]
8), This works in works construct too.
I am going to a start using python lot more. :D
B
21
S
4
G
4
Posts: 280
Reputation: 2,934

Post » Wed Jan 13, 2010 10:44 pm

Yeah you can create a window with Python. Matter of fact the window doesn't have to be directx.
Useful for some things, but I don't think it can get the same speed as the Construct window.
Image Image
B
161
S
48
G
90
Posts: 7,356
Reputation: 66,767

PreviousNext

Return to Your tutorials & example files

Who is online

Users browsing this forum: No registered users and 1 guest