8

我刚开始学习搅拌机及其脚本并尝试运行它的示例代码

import bge


def main():

cont = bge.logic.getCurrentController()
own = cont.owner

sens = cont.sensors['mySensor']
actu = cont.actuators['myActuator']

if sens.positive:
    cont.activate(actu)
else:
    cont.deactivate(actu)
main()

并得到以下错误: ImportError: No module named 'bge' 我搜索了解决方案但找不到任何模块。如何解决这个问题?我正在使用搅拌机 2.65

4

2 回答 2

11

当您按“运行脚本”或尝试在终端中发出此命令时,运行 import bge 不起作用。您必须按“P”来激活游戏引擎模式。要运行脚本,请将控制器连接到脚本。

于 2013-02-02T17:08:25.480 回答
0
  1. import 'bge' 必须是 'blender game',而不是 blender 渲染
  2. 在“游戏逻辑编辑器”中给出“始终”运行 python 脚本
  3. 开始游戏
于 2018-01-04T03:30:05.690 回答