[SOLVED] Python broken/confused? (Construct v1.2)

For questions about using Classic.

Post » Wed Jun 01, 2011 12:02 am

Straight to the point: I did some testing on a newly created empty Direct-X application project, after something never seemed to work in another project file and I couldn't figure out why.

Basically this is what I have:
Start of Layout Event -> System:Run Script ("array1 = [1,2,3,4,5]")
Script: [code:tup5wvjd]import random
if MouseKeyboard.OnKey('A'):
Sprite.SetValue('sizeaccel', (random.choice(array1)))[/code:tup5wvjd]

Now, what happens? When I press 'A' - nothing happens at all.
So how do I assign a new value to 'sizeaccel' with this code? - Clicking the left mouse button. :)

Am I confused, or is the program confused? I mean, I only just started learning python, but this seems weird to me.

EDIT:
No matter what Key, it always only sets the value on the left mouse button click.
AND I tried another function, MouseKeyboard.AnyKey() - This one is even better, the 'sizeaccel' variable now spins through all numbers in 'array1' every step, without doing (pressing, clicking) anything at all.

Thanks in advance!
B
3
G
1
Posts: 70
Reputation: 615

Post » Wed Jun 01, 2011 12:12 am

import random
if MouseKeyboard.OnKey('A'):
Text.SetText("Hi Mom")
Sprite.SetValue('sizeaccel', (random.choice(array1)))


Create a text object and use it to debug your program and you can use the debugger as well. For example, to see if your code is functioning right you can put a SetText call to see if that code is reached. I don't have Construct with me at the moment so not sure your syntax is correct or not....but you should try setting the 'sizeaccel' value to let's say "1" to debug that portion of your script.

I think you need a "do once" type event for this as well since you only want that code executed one time you press the A key.

EDIT: This post will help you (this question sounded familiar ;-)

viewtopic.php?f=3&t=6339&p=50387&hilit=mousekeyboard+python#p50387
B
8
S
3
G
7
Posts: 835
Reputation: 5,313

Post » Wed Jun 01, 2011 5:19 am

I see! Thank You for the on point help!
B
3
G
1
Posts: 70
Reputation: 615


Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 3 guests