FANDOM


BGE Python scriptingEdit

Use of python scriptsEdit



Q

When I write a script do I just select an object then paste the code for that object I wrote in the script or python window? See thread scripting



A

You write the script in the text window, then you put a sensor on the object and a python controller that links to the name of the script.

MouseEdit

Show mouse cursorEdit



Q

How to show the mouse in the GE? See thread mouse



A

Simply activate the default mouse cursor, you use this Python script:


import Rasterizer
Rasterizer.showMouse(1)

ObjectsEdit

Add new objectsEdit



Q

How to add new objects in the GE? See thread How to create new objects with an Actuator



A

The "template" object must be placed on an hidden layer. It will be inactive when running the GE. From the template instance objects can be created by copying. There are multiple ways:

  1. By Edit Object actuator in Add Object mode. Add the name of the template object in the OB: field. The new object will get the position and orientation of the object that added it.
  2. By the Python function instantAddObject() in conjunction with the above Add Object actuator. See API.
  3. By the Python function KX_Scene.addObject(object, other, time=0). See API

Keep in mind:

  • The template object should be on an hidden layer.
  • The template object is inactive and will not execute any logic.
  • Actuators and sensors that have the template assigned as parameter during desing time will keep this reference at runtime. They will NOT reference to new instances!
  • The new objects are copies of the inactive template. The instances are active and execute their logic.

Ad blocker interference detected!


Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.