8 years using blender and still, never tried the Python API. Never too late to begin! Then I was stuck on something very frustrating, tried 2 days, created variant, searched for bugtracks and looking for others stack thread.
The context
I'm working on a "civ-like" game with tiles. To generate my map I want to run a small "buildmap.py" script allowing to place tiles and control them.
So, I put the tiles and tiles variant on my second layer and call them from the first layer with a "spawner" Empty object at the launch of the scene:
Always (tap) -> python : buildmap.py
Here is the code :
import bge
world = bge.logic.getCurrentScene()
world.addObject("Tile", "spawner",0)
The problem
When I launch the game everything looks good, the tiles are placed at the right places. Then I clicked on the first one... And realized that my script putted 2 "Tile" objects on each position. I removed the loop to study the addObject and branch it to a keyboard with same result. By calling once addObject it places 2 objects.
Maybe I’m missing something ? so I came here :)