1
$\begingroup$

I have a game which is a car moving forward on pressing the up arrow and stops on pressing the down arrow. I need to change the game control. I want to use a matlab file as input.
This file contains a function, when the function = 1 car moves when it's 0 the car stops.

import bge
cont = bge.logic.getCurrentController()
own = cont.owner
move = cont.actuators["move"]
pressup = cont.sensors["up"]
pressdown = cont.sensors["down"]
speed = move.dLoc[1]

if pressup.positive:
  speed = speed + 0.05
  move.dLoc = [0.0, speed, 0.0]
  cont.activate(move)

elif pressdown.positive:
  speed = 0
  cont.deactivate(move)
  move.dLoc = [0.0, 0.0, 0.0]
$\endgroup$
2
$\begingroup$

Indirect Control

I suggest to first exchange the keyboard sensors by message sensors. You do not even need to change your car controlling code.

enter image description here

to

enter image description here

To make it working, you now need a "user input provider" (other object) to send the new messages.

enter image description here

Note: the True Level Triggering. This is necessary to continuous send the messages as long as the key is held.

Now your game should act as it did before

File input

Now you can add a request provider that does not listen to the keyboard, but reads a file and sends according messages with the right timing. Be aware this is a continuous process. You should send a message (of on subject) just once per frame.

You need to process file operations via Python. How to do that is a different topic.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.