3
$\begingroup$

I can not get Python to work, I have followed YT videos and do exactly what they have done but I only get error message:

No module name 'bge'

I have searched on Google, but I cannot find similar answers. What is wrong?

At the top of my script I do have import bge

Although, I read somewhere that the inport BGE has changed.

But I'd really like to get this to succeed. I can get my game to work without python but I'd rather not and it would make it too complicated.

I'm using version 2.77.

Here is my blender file

And this is the Script I trying

import bge


def main():

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

    message = cont.actuators["message"]
    remove = cont.actuators["remove"]

    own.text = "I don't want to talk."

    if own["time"] > 0:
        own["time"] -= 1

    if own["time"] <= 0:
        cont.activate(message)
        cont.activate(remove)   

main()

Also this is the youtube clip I follow. https://www.youtube.com/watch?v=8klSGN1m5no&list=LLi0N8WDVMrYgCK_ni5ajv5g&index=5

$\endgroup$
  • 1
    $\begingroup$ another bug I have seen is in the text editor properties panel(ctrl+t) some times I get this error if "live edit" is checked as True. $\endgroup$ – JustinBarrett Jun 18 '17 at 10:43
2
$\begingroup$

BGE is lower case when used in python.

Try;

import bge

Also make sure you are running your script inside the game engine rather than with the 'run script' button. The 'run script' buttons is for addons. To run a script in the game engine you use the python controller logic brick.

$\endgroup$
  • $\begingroup$ Thanks for the reply. (And I write "bge" lowercase do not know why it is with big here ...) But I manage to make it that I want to get python to do with logic brick. So I intend to run on it. But it is sad that I do not get Python to work. Maybe there is something wrong. Can I send over the python script I'm trying to get to work. So anyone can check if there is something wrong. $\endgroup$ – Robin Willmann May 23 '16 at 9:51
  • $\begingroup$ See the second part of my answer. But yes, attach the script to the first post so we can have a look at it. $\endgroup$ – sdfgeoff May 23 '16 at 10:04
  • $\begingroup$ Thanks again. Yes i have done that. I just press the run script to see if it works that way. but I think i understand I should not press the run script... I may have forgotten to select actor for my npc. Therefore, the near sensor don´t work. therefore does not the script work. I'll check it out. But I'm at work now. So have to wait until I get home .. (I tried to get another near sensor to work but it would not move. so I searched and then I saw that the "cube" must be an actor ...) $\endgroup$ – Robin Willmann May 23 '16 at 10:33
0
$\begingroup$

I've got it working now. apparently it was logic brick "scene" was wrong. it was apparently have to be named "remove" So it says in the script. I had left the name "scene" therefore error.

do not know what I'm doing now. But I have myself solved my probelm.

But thanks anyway

(I will return soon .. have another problem, I need help I will never figure it out ...)

$\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.