Page 1 of 1

Need a non-crashing "endless" loop

Posted: Fri Dec 15, 2006 11:14 pm
by cerbellum
*UPDATE: first problems solved - work work!

Hi all,

Now that 2.5 is final (great job!), I'm off to start working on my modules again.

The module I'm currently working on reads a string out of a text file, the problem is that the string in the text file changes continuously (externally generated X-Y-Z coords) and I want to read the file continuously too or let's say at a given framerate (24fps) so I can use the externally generated coords in realtime (fe. using the coords to rotate a modul8 generated cube)

I've been trying to do it with while/for loops but as there's no end to the loop, modul8 crashes. It's probably something with a periodical event but I have no idea how to do it.

I'm using:

Code: Select all

//init
file = open('textfile.txt', 'r') //opening the file
txt = file.readline() //reading the first and only line
txt = txt.split(';') //splitting the string as the coords are divided by ';'
print txt //console print for checkup

k = 'testvar'

// I tried things like
while k == 'testvar': //which it always is, so it'll continuously do the following
    file.close()
    file = open('textfile.txt', 'r') //opening the file
    txt = file.readline() //reading the first and only line
    txt = txt.split(';') //splitting the string as the coords are divided by ';'
    print txt //console print for checkup

//but quite logically it crashes


Help seriously appreciated and thanks in advance

Thanks,
Kevin

Posted: Sat Dec 16, 2006 12:08 am
by cerbellum
Ok so I found it out myself



Code: Select all

count += elapsed

if count >= 0.04 : #update each second
   count = 0.0
   file.close()
   file = open('textfile.txt', 'r')
   txt = file.readline()      
   txt = txt.split(';')
   x = txt[0]
   x = int(x)
   module.setValue ('accX',0,x)
   y = txt[1]
   y = int(y)
   module.setValue ('accY',0,y)
   z = txt[2]
   z = int(z)
   module.setValue ('accZ',0,z)


I'll keep you posted on the purpose of this thing!