I am trying to create my own sensor block in Blender's Game Logic to detect a text file being created in my C drive by another program.
Is it possible to perhaps hack an existing sensor or to create a new one in which you can define where the text file is located?
I tried using the suggested answer method stated below, but the python code would only run once upon finding the variable in the test.txt file. Any ideas on how to keep the always loop running? Here is some sample code:
import bge
from bge import logic as GL #GL=GameLogic
import os
import re
# Get the whole bge scene
scene = bge.logic.getCurrentScene()
cont = GL.getCurrentController() #access the logic brick that the script is being called from and assign it to a variable
#logic brick is returned by getCurrentController() -this method is passed to the variable cont
own = cont.owner #accessing the Armature object that is the owner of the controller
#Sensors - now have access to the controller and to the object that owns it. The next thing to do is to retrieve the necessary sensors
AlwaysSensor=cont.sensors['Always1'] # sensors assigned meaningfully name variable
#Actuators - retrieval of the actuators
box_action = cont.actuators["Action1"]
#Now all the necessary logic brick components are accessible within the script, and the code for the movement itself can begin.
#setting up Action - animations
box_action.action = 'upMovement'
box_action.frameStart = 1
box_action.frameEnd = 24
box_action.mode = 2 #play modes are represented by integers: 0 represents the Play play mode, 1 represents the Property play mode, 2 represents the Flipper play mode, 3 represents the Loop Stop play mode, and 4 represents the Loop End play mode.
print("writing read charcters")
#note text file is in blender file in C drive
text_file = open("test.txt", "r")#varialbe=parameterOpen(parameterFileName, r read)
#print (text_file.read(1))#prints the first character '1' in txt file
var=(text_file.read(1))
print ("var=", var)
if (var == "a"):
#if (text_file.read(1)) == 'h':
if AlwaysSensor.positive:
cont.activate(box_action)#run upMovement animation
print("a found+animation run")
text_file.close() #closes the file once read
Here is a screenshot of the game logic blocks setup: