Doubt with script

Anyone can create a blend with this script.

import Blender,datetime

#Write date and time the variable
data_recorded = str(datetime.now)

Creating or opening the file

f = file(‘C:\date_recorded.txt’,‘W’) #Open for writing

Write to file

f.write(date_recorded)
f.close() #Close file

while True:
line = f.readline()
if len(line) == 0:
break
print line,

If I remember correctly used to record names and hours.

I wanted him to record many names as in the example below:

Name :************
Password :*************
Hours :***********

And if one of the data were equal, activates an actuator

Please help me, this is very important!

I’m not sure, not having a good grasp on python, but it looks like youre trying to import the blender section of python instead of the bge part. You cant use the blender modules in real time

There are a few problems with this script:

  • As Rorkimaru said,you’re using the Blender module, which is not available in the BGE.
  • The while True loop will prevent the ge from running (it wont continue until the script finishes), effectively freezing the ge.

He has a method to break out of the loop (the if len(line)==0) but you could just do while len(line) != 0 instead.

You might need to import things like file, and some sort of read/write function? I’ve always just used pickle.

A few things:

datetime is a weird, weird class, and it doesn’t seem to store the methods for creating instances inside of just datetime. In order to use the now() function, you have to do either


import datetime
a = datetime.datetime.now()

or


from datetime import *
a = datetime.now()

You also call your first variable data_recorded, but then try and write date_recorded.

To read again from the file, you have to re-open it with


f = file('C:\date_recorded.txt','r')

I hope that helps!

-Sam

It is better to give up this script, it very difficult. I’ll try another way. Does anyone know if this is possible:
I have a text, then write a name, I click enter, that line, write another name. If this line is equal to one of the previous lines triggers the actuator.
I apologize for the many doubts about python, because I do not understand almost nothing.
Thanks guys