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

This forum is currently in read-only mode.
  • 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:

    import random
    if MouseKeyboard.OnKey('A'):
    	Sprite.SetValue('sizeaccel', (random.choice(array1)))[/code:tup5wvjd]
    
    Now, what happens? When I [b]press 'A'[/b] - [b]nothing happens[/b] at all.
    So how do I [i]assign a new value to 'sizeaccel'[/i] with this code? - [b]Clicking the left mouse button[/b].   
    
    Am I confused, or is the program confused? I mean, I only just started learning python, but this seems weird to me.
    
    [b]EDIT:[/b]
    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 '[i]sizeaccel[/i]' variable now spins through all numbers in '[i]array1[/i]' every step, without doing (pressing, clicking) anything at all.
    
    Thanks in advance!
  • 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

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • I see! Thank You for the on point help!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)