Hey guys,
I decided to work into the BGE. I have learned a lot by following tutorials etc., but now I came to several problems which I cant fix alone.
I wanted to make a really basic strategy game. Therefore I needed a Spawner for my Buildings. It should spawn buildings on random, but appointed positions.
I figured I could solve this by making Spawnplatforms which will be randomly selected by my spawner.
For everyone who does not need the .blend to see the problem here is what I’ve done so far:
#leftclick triggers the script
from bge import logic
from random import randint
def main():
scene = logic.getCurrentScene()
cont = logic.getCurrentController()
own = cont.owner
objs = scene.objects
#counting the number of platforms
num_platforms = -1
for item in objs:
if 'platNum' in item:
num_platforms += 1
#all possible platforms
existing_platforms = [scene.objects["spawnPlatform.000"],scene.objects["spawnPlatform.001"],scene.objects["spawnPlatform.002"],scene.objects["spawnPlatform.003"],scene.objects["spawnPlatform.004"],scene.objects["spawnPlatform.005"],scene.objects["spawnPlatform.006"],scene.objects["spawnPlatform.007"],scene.objects["spawnPlatform.008"]]
#choosing a random platform
randomNumber = randint(0,num_platforms)
randomPlatform = existing_platforms[randomNumber]
#display number for debugging
objs['houseSpawner']['number'] = randomNumber
#moving cursor in 'spawn-position'
spawn_input = cont.sensors["event"]
if spawn_input.positive:
own.worldPosition = randomPlatform.worldPosition
### del existing_platforms [randomnumber]
I have 3 problems at once right now:
-
The randomly generated platform in my Code does not match the actual onscreen platform. This was once the case, but I dont know what led to that Error.
-
The most important part - I am not able to delete the platforms out of my list, after they have been “visited” by my spawner. Because of that my buildings would stack over one another. I tried using “del existing_platforms [randomnumber]” but it did not work out.
-
I was wondering if there is a good way to automatically add my platforms into the existing_platforms list. If I want to add further platforms I would not like to individually put them in my list.
If anyone knows a solution to one of my problems I would already be thankful
One more thing: As I stated I am really new to coding. So please explain it as you would explain it to a child
And my code will probably hurt your eyes due to my noobness ^^
if I violated any rules I am really sorry, for I this is my first post.
Greetings from Germany!
Gee
[ATTACH]424697[/ATTACH]