How do I know if Create Object (by name) failed?

  • Hi, I'm wondering if anyone knows a way to detect when the Create Object (by name) fails to create an object because the string it was passed isn't valid. In most languages, you'd be able to write some logic like, "If this function call returns true, do this, otherwise do that", but I don't think there's a way to get a return value from the built-in system actions. Anyone know if there's something I'm missing? Thanks.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • OK, naturally as soon as I ask for help, I come up with a workaround. So, if anyone else is doing something similar, hopefully this will be helpful.

    I made a function called SpawnCharacter, which creates instances of characters based on a CharacterType string parameter, and returns either the UID of the new character, or zero if a new character wasn't created. The logic of the function goes like so:

    • Declare a lastSpawnedCharacter_UID local number variable.
    • Pick the last created Character object, and set lastSpawnedCharacter_UID to Character.UID.
    • Create Object (by name) using CharacterType.
    • Pick the last created Character again.
    • Compare the UID of the last created character to the value in lastSpawnedCharacter_UID.
    • If the values are different, return the UID of the last created character.
    • If the values are the same, return 0.
Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)