Repository: 4ian/GDevelop
File: newIDE/app/src/EditorFunctions/index.js (JavaScript)

Code before:
        ', '
      )}.`;
      return propertiesText;
    };

    const createNewObject = async () => {
      // Check if object already exists.
      let existingObject: gdObject | null = null;

      if (layoutObjects.hasObjectNamed(object_name)) {
        existingObject = layoutObjects.getObject(object_name);
      } else if (globalObjects.hasObjectNamed(object_name)) {
        existingObject = globalObjects.getObject(object_name);
      }
      if (existingObject) {
        if (existingObject.getType() !== object_type) {
          return makeGenericFailure(
            `Object with name "${object_name}" already exists in scene "${scene_name}" but with a different type ("${object_type}").`
          );
        }

        // /!\ Tell the editor that some objects have potentially been modified (and even removed).
        // This will force the objects panel to refresh.
        onObjectsModifiedOutsideEditor({
          scene: layout,
        });
        return makeGenericSuccess(
          `Object with name "${object_name}" already exists, no need to re-create it.`
        );
      }

      const targetObjectsContainer =
        target_object_scope === 'global' ? globalObjects : layoutObjects;

      // First try to search and install an object from the asset store.
      try {
        const { status, message, createdObjects } = await searchAndInstallAsset(
          {
            objectsContainer: targetObjectsContainer,
            objectName: object_name,
            objectType: object_type,
            searchTerms: search_terms || '',
            description: description || '',
            twoDimensionalViewKind: two_dimensional_view_kind || '',
          }
        );

        if (status === 'error') {
          return makeGenericFailure(
            `Unable to search and install object (${message}).`
          );

Review comment (suggestion):
Might be worth writing something like
```suggestion
            `Object with name "${object_name}" already exists globally but with a different type ("${object_type}").`
```

(needs a boolean to remember or check where it's coming from, but worth it I think for a LLM that is freaking out)

Code after:
        ', '
      )}.`;
      return propertiesText;
    };

    const createNewObject = async () => {
      // Check if object already exists.
      let existingObject: gdObject | null = null;
      let isGlobalObject = false;

      if (layoutObjects.hasObjectNamed(object_name)) {
        existingObject = layoutObjects.getObject(object_name);
      } else if (globalObjects.hasObjectNamed(object_name)) {
        existingObject = globalObjects.getObject(object_name);
        isGlobalObject = true;
      }
      if (existingObject) {
        if (existingObject.getType() !== object_type) {
          if (isGlobalObject) {
            return makeGenericFailure(
              `Object with name "${object_name}" already exists globally but with a different type ("${object_type}").`
            );
          }

          return makeGenericFailure(
            `Object with name "${object_name}" already exists in scene "${scene_name}" but with a different type ("${object_type}").`
          );
        }

        // /!\ Tell the editor that some objects have potentially been modified (and even removed).
        // This will force the objects panel to refresh.
        onObjectsModifiedOutsideEditor({
          scene: layout,
        });
        return makeGenericSuccess(
          `Object with name "${object_name}" already exists, no need to re-create it.`
        );
      }

      const targetObjectsContainer =
        target_object_scope === 'global' ? globalObjects : layoutObjects;

      // First try to search and install an object from the asset store.
      try {
        const { status, message, createdObjects } = await searchAndInstallAsset(
          {
            objectsContainer: targetObjectsContainer,
            objectName: object_name,
            objectType: object_type,
            searchTerms: search_terms || '',
            description: description || '',