Stopping the adding of a cube

Hi there.

Here I can not yet solve a simple problem - how to stop adding (moving) a cube, provided that one cube is already in this place? The conditions of the pulse mode are necessary.

example - cube_birth01.blend (474.4 KB)

Thank you for attention.

use a property?

if not 'cube_added' in own:
    added = scene.addObject(cube,spawn,0)
    own['cube_added'] = True
    own['last_added_cube'] = added #store last added cube

As if the problem is … let’s say if an object overcomes a certain distance, a new cube was added to the new position, but only once. Probably what you wrote does not quite fit.
Probably I need to rephrase the question - can I check the given coordinates for the presence of a cube (object) there, and if there is not, create it?
Thank you for your reply.

This will be hard, because in normal conditions you do not know if there is a cube.

What you can do is add a cube, store it location in a list, then loop trough the list and check the position with the new cube’s position, then if that position is in the list skip adding cube and go to next position.

What are you trying to make?

Should use a near or collision sensor, in the code check if that sensor is true, if so don’t create a cube.

Also you will need to enable a collision type for the object.

if you add a cube, set a property = cube object.

if spawner.get("newobj", None) != None:
    dist = spawner.getDistanceTo(spawner["newobj"])
    if dist > 2:
        spawner["newobj"] = None

else:
    # run code to add new cube
    spawner["newobj"] = spawner.scene.addObject("Cube", spawner, 0)
  • How to do this - the code?
  • an infinite level of tiles (objects of a fixed size), based on the position of the player.
  • thank you for a very interesting (new for me in the knowledge :thinking: ) code, but it is not entirely suitable for my task… maybe, I need to think more.

Ah ok, not gonna write that for you, but here is an example.


position_list = []

def build(cont):
    
    own = cont.owner
    spawner = own.scene.objects['spawner']
    
    if not position_list:
        add_object(cont,spawner)
        return

    if not spawner.worldPosition in position_list:
        add_object(cont,spawner)
    
    
def add_object(cont,spawner):
    
    own = cont.owner   
    last_added = own.scene.addObject('Cube',spawner,0)
    position_list.append(last_added.worldPosition)
    spawner.worldPosition.y += 1.0

in this case, the list only stores location of the cubes you have spawned, so you can use it later.
but this is basically the basics to add cubes in a straight line.

You can add an in range() check to add squares, but to keep it around the player is a completely other story.
best is to look into resources, should be some scripts there ready to go. for example: dig world problem

  • you wrote - “is an example” - I can use it as a tutorial to create my own example with the license CC0? For example, for me the concept of “return” is new …
  • you wrote - “best is to look into resources” - if someone has laid out the code in response to a question (part), it will still work, and then you can catch on. But basically on the forum ready-made solutions (files) - there is completely copyright of the owner. Search for everyone and ask … I can, but it’s very difficult.
    In general, in some forums clearly spelled out - the answers of users under the license - such and such.
    Thank you for attention.

People and their license issues lol, yes of course use it anyway you see fit,

The return breaks up/stops a function for a frame, if i would not have added the return, then in the first frame it would execute all the code, now with the return it will execute the first part on the first frame, then on frame 2 it will execute the rest of the code and skipping the first code block, because at frame 2 the position_list got an entry.

Yes and no, if someone shares a solution to the public then everyone may use it, the code/blends/etc are automatically licensed as a public one. and you can simply add credits to the one who made it. Just don’t brag about it that you are the maker of the code, because if you do then you are breaking the public rules.

If i am right the link i posted has what you want/need, so you can PM @VegetableJuiceF and ask if you may use it, if you aren’t sure about it.

  • Thank you for permission to access, and an explanation.
  • yes, because the Law says differently, and for this there is a CC0 license. If you do not specify a license, then all the work of the copyright to owner - it’s not I came up with, it’s an international Law.

Thank you for attention.

No problem,

To add some more info about the ‘return’ command.
It is also used to pass information(variables) to other functions like this:

def give_answer():
    answer = 'yes you may use anything'
    return answer

def get_answer():
    answer = give_answer()
    print(answer)

so get_answer calls the function give_answer and that function returns the answer.

Also if you use BGE module in your python scripts then they are licensed under GPL keep that in mind.

  • thank for the addition.
  • A little bit probably not so - BGE is GPL, blend file - structure and format of GPL, work is mine. As in any editor, even that Word is all under MSoft, but the text of the user is not. The same as GIMP files, Audaсity …
    And probably a very urgent issue - a compiled binary with a scene and BGE:
  • if I create an executable ZIP file, this does not mean that everything is under the archiver’s (module) license. Similarly, the binary is an archived archive with BGE and the scene, and everything is under its own license.
    Just there were such cases (not me) that opened the binaries, and there BGE + scene. The compiled file, it’s not BGE, but some executable archive with the sources and the executable file BGE. It seems I was not mistaken anywhere.

Thank you for attention.

look at what i have posted here:

  • if the binary file inside is divided into two components - the blend file, and the BGE binary, then this statement is not even legal. I do not think that there is a recompilation and some kind of crazy mix of the code of the main BGE. How can an executable archive (attachment) become an archiver license? No way! Forgive me for this reasoning.