External driven data

I have been using the game engine to fly and object that has received external data to create ipo information. The data I have consists of time, position, and euler angles. Once the ipo for the object has been created, I use the ipo actuator to propogate the object.

I need to see if there is a way that the game engine has a way of collecting the data instead of a predetermined ipo.

Does anyone have examples of using the python controller to collect external data and use it to propagate objects? I want to make an exacutable so that anyone who does not know blender can place data in a specified directory and run the .exe to see the results of the flight. I do have 2.25 publisher.

Thanks,
KingJames

Not exactly sure I understand you, but I assume you understand python since you are doing stuff like saving information to ipos. Here are some realtime blender commands to apply the kind of data you want to an object:

object.setPosition([x,y,z])
object.setOrientation(orientationmatrix)

eschlo wrote a script to convert euler angles to the orientation matrix, search the python forum for eul2mat or euler to matrix, and you should find it.

I wrote a script that takes data from a text file and “builds” an objects ipo. I then take that ipo information and place it in the game engine. When I hit p to play, the object “flies” according to it’s ipo. This works as I expect it to.

Because people watching the object fly around (with real data from my text file) don’t know how to use blender, they won’t know how to load the ipo data each time I get a new data text file. I want to be able to let them drop the data text file in a directory, run the real time executable, have the executable load the position/angle info for the given time stamp in the data text, and have the engine fly the object. That way, they don’t have to know how blender works. Can python in the game engine read external data to load into objects? Any examples?

As for the eul2mat info…thanks, I’ve been looking for that!

Thanks for your help saluk (and anyone else).

-In the last game I posted
http://members.xoom.virgilio.it/glabro1/MountainRace.zip
there’s an example of it.But I didnt use external data because it slow too much Game engine.I’ve copied the data in the script using it as list.

Wow, lot of hard work in this game! I’ll try to write a script that opens a file, reads it and puts it in an array similar to the coord array in the FollowPath1 script.

Thanks again!

Hello Ben
Really nice game, the Mountain Race!!
Almost beat the Sega Rallye :slight_smile:
Good work
António

Yeah, the realtime game engine can read from external files as these functions are built into the base of python.

The default directory where files are saved are the same directory as the blend if you open it up directly (which is what I assume youll be doing for distribution) and in the blender.exe directory if you open the file up from within blender.

here is a sample:


#To write:
f = open("myfile.txt","w")  #The w indicates that we are writing, it will overwrite any info in the file
f.write(str(mylist))  #Converts the list to a string and writes it
f.close()  #Frees file from memory

#To read:
f = open("myfile.txt","r")  #The r indicates that we are reading from it
mystring = f.read()  #Reads in all data from the file as a string
mylist = eval(mystring)  #Converts the string data back into the list we can use
f.close()  #Frees the file again

Thank you OTO!!

Sorry to dig up this old thread, but I found this info very useful.
Could this be hooked to HTML? Like PHP or ASP can read parameter from a url (http://…asp?3)

Mmmh looks intresting, now I try to ask a question I tried a lot of times, how to write the error from the blender console, or runtime into a txt file? So they can looks aftherwards into it to check what was wrong. Seams to be usefull because the blender console doesn’t handle a lot of lines, so you can’t read the all when it gives a lot of logic bricks or python errors. :slight_smile:

JD-multi: I dunno about saving it directly to text, but in Windows 2000 and likely XP, you can increase the buffer on the console window to 9,999 lines.

Just right click on the window’s taskbar icon, go to Properties, Layout, and change the buffer size.

PS, if your game has more than 9,999 errors, you have a problem :wink:

there are several ways

one:
blender > outputfilename.txt
another:

import sys
ofile = open("ouputfilename.txt")
sys.stdout = ofile
sys.stderr = ofile

and that is probably enough to worry about. with the second method it will probably not show up on the console, but it is what you would do if you were making a python console running entirely inside of the game engine
[which I started working on but never made any good progress]

Thanks z3r0 d, I got it to work, but I added the “w” function otherwise it didn’t work, it said, no directory or filename when I didn’t add the “w” function. But I’m happy I learned some more python. :smiley:


import sys
ofile = open("myfile.txt","w")
sys.stdout = ofile
sys.stderr = ofile

yes, open(“somefile”) is for opening an existing file for reading. It’s really a shortcut for open(“somefile”,“r”). open(“somefile”,“w”) will open a file for writing. Beware, if the file already exists, it wont warn you, it will just overwrite it. THere are other modes for open as well but they usually aren’t necesary.