Setting amount of total objects in scene

I have a scene and I have it set up so only 8 objects can be added to the scene (that is all I want to add total).
I have made different objects now so I want to set it up with logic bricks, if possible that only 8 total will ever be in scene. To explain it better let’s call my objects A,B,C and “D”. If I add 1 “A” object and then let’s say 2 “B” objects and 1"C" object, I should only be able to add 4 “D” objects, so no matter what the combination of objects I add the total in scene will never be more than 8. If it can be done a example blend would be great so I can see the LB hookup. Thanks

digiman

not hard, use a property that counts the added objects.

just keep track of the count with a property.
add object and set a property +1

use a property sensor, connect it to all actuators that ads an object.
Then simply add the info like: property sensor less then 8, so if the property is equal to 8 it will not add more.

Or instead of a property sensor you can use an expression brick, instead of the AND brick and put in the following: property_name < 8

so: your sensor -> expression -> add object and your_property +1

this might work also

if len(scene.objects) &lt; 8:

Be aware the above methods count the total amount of all game objects. This includes lights, cameras, empties etc…

You might want to filter the objects a bit more e.g. total amount of objects that have the property “addable”.

Hooking those bricks up the way you describe does not seem to work. It works fine for one object but I can’t get it to work for the objects I want to add, that is why I wanted an example blend or a diagram to see hookup.

digiman

well its exactly how i said it, and that works. so i guess you did mis something.
Anyway here is a blend with 2 objects.

untitled.blend (481 KB)

Here is the problem with your blend ( I made a few changes) Right now for one object only, on my project I have the property
as you do and a message brick so when I add that one object (I can add as much as 8), if I delete a few of those objects, then decide to include them back into scene I can do that. With your blend you can add up to 8 objects. let’s say 4 red and 4 green, then I decide to delete one or two greens cubes, I can’t add any more green or red objects after that, that’s what I need so the total scene never has more than 8 objects.

http://www.3dfishworld.x10host.com/untitled.blend

digiman

I want to set it up with logic bricks

In this case, you can not do this with logic bricks.

Info:
Once you put a keyboard sensor on the cube, all cubes with the same key will be removed.
and with the use of a message only 1 will be subtracted for each color, so 2 in total, this let you spawn 2 new ones only (8-2=6).

You need to handle this task with python, you add it to a list, at this point we know exactly what cubes we have. Then we can just grab the first one in the list to remove it, or a random one, etc.

Here is a working example with 2 cubes with keyboard bricks and python.
untitled (1).blend (504 KB)

Have fun!

Yeah that is what I was looking for but my project is using 2.49b. I know what you are thinking W.T.F why still that old version? Here is why, about a year ago I decided to finally learn 2.7 I thought the best way of learning was to model an object in 2.49 which I know well, the model the same object in 2.7, add an armature in 2.49 then do the same in 2.7, etc but 2.7 was so buggy on my system, I tried a newer build for 2.78 but still buggy as hell, so I tried 2.76b, figuring that is just as good for my needs but again problems. After 2 weeks of trying I gave up but my project was looking pretty good in 2.49b. Maybe there is a way to do it with LB, I have been fooling with LB for a few days now but maybe someone else might know.

Thanks anyway
digiman

you shouldnt pass blend files between versions.

2.74 is my current favorite. the biggest issue ive found is the solid colors glitch in edit mode at times.

alot has changed, maybe the bugs you are experiencing are intentional changes. dont be afraid to ask questions in the support sections. blender needs more bug smashers too.

Here is a Demo that restricts the emitting of objects dependent on the amount of objects with the property “emittable”.

The code is this:


import GameLogic


MAX_EMITTABLES = 8


PROPERTY_EMITTABLE = "emittable"


controller = GameLogic.getCurrentController()


# behave like an AND controller
if all(sensor.positive for sensor in controller.sensors):




    emittableObjects = [object for object in GameLogic.getCurrentScene().objects
                        if PROPERTY_EMITTABLE in object]
                    
    numberOfEmittables = len(emittableObjects)


    canEmit = numberOfEmittables &lt; MAX_EMITTABLES
    
    if canEmit:
        for actuator in controller.actuators:
            controller.activate(actuator)    
        
else:
    for actuator in controller.actuators:
        controller.deactivate(actuator)                        

The logic should look like this:


sensor -&gt; controller Python script: canEmit -&gt; actuator

Attachments

resticted emit demo.blend (220 KB)

does it have to be in different datablocks, the way you set it up for your script to count objects?

digiman

My script?

No it’s not needed, but makes things easier.

1 function to add object.
1 function to remove object that passes arguments to a second function who executes the code, this prevents repetitive code. now you just pass a list instead of copy/pasting the code for every cube sort you use.

No.

The script is designed to count objects with the property “emittable”.

When there are 8 or more objects with that property the Python controller will not activate the connected actuators. If it is an add object actuator - it will not add objects.

The demo shows you how you can use it on different emitter emitting different objects (which have the property “emittable”). I’m sure a single emitter will satisfy your current requirements of a single emitter. So grab one and append it to your .blend file.