Python 'threading' in CC

This forum is currently in read-only mode.
  • Does Construct Classic supports python threading module?

    I need it to use 'time.sleep()' without freezing of application and it works great in my python IDE, but doesn't work in Construct =

    http://dl.dropbox.com/u/24325446/pyThreading.cap

  • try the Timer() instead of sleep():

    Timer(3.0, yourfunction).start()

    I'm not sure, but I think sleep() is allways will freez the whole process - but as I said, I may wrong.

  • I tried threading.Timer, but I can't figure out how to make it work inside of a loop and with function's args

    sleep() freezes only thread, this is why I'm trying to use it in separate threads, and as I said, it works in IDE and promt, but doesn't in Construct

  • OK, I just found how to deal with Timer ()

    from threading import Timer
    
    def run (input, delay):
        for i, ch in enumerate(input):
            t = Timer(delay*i, prnt, (ch))
            t.start ()
    
    def prnt (txt):
        print txt
    
    a = "abcdefg"
    run(a, 0.2)
    
    

    <typing letters with delay of 0.2>

    But, again, it works only in Python BUT doesn't work in Construct!

    In Construct (with "Text.text+= txt" instead of "print txt") it adds only first char of string.

    So, Construct doesn't support threading module? If so, how can I implement timer with Python?

  • The reason it doesn't work is because Python is not run continuously, it's only run for the duration of the script and then control is given back to construct. You need to add a python script to be run every frame. It can be something as simple as "#".

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Oh thanks, it works now!

    You are Construct\Python guru, I had no chances to solve this on my own

  • I have wrote a timeline in python before.

    sites.google.com/a/binhua.twbbs.org/construct-project/FileStorage/timeLine.7z

    Here is a sample code to

    1. flash a sprite object immediately

    2. then wait 2 second

    3. rotate the sprite each 0.01 second

    def test_iter(timer, obj):

        obj.Flash(0.1, 1)

        timer.delay_time = 2

        yield QTimer.CONTINUE

        timer.delay_time = 0.01

        while(1):

            obj.RotateClockwise(1)

            yield QTimer.CONTINUE

  • Awesome.

    What module are you using, it's your own or parts of some library?

  • Yes, it's my own. All of these source files are put in zip file.

    The concept of timeline is simple.

    At each tick:

    1. get current time

    2. pick timer which is time-out.

    3. execute callback function of timer picked in step2

    A performance issue is, it need call python function each tick.

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