0 Favourites

Returning an Object/Array Expression?

  • I'm creating a type of "inventory" behavior that gets attached to a sprite. This would primarily be used in RPG-style games. I currently have things like "size of inventory" and "add item." It also has expressions that can be accessed like "Player.Inventory.NumberFilled." What "add item" does is ask the user for a slot, name, and sprite. Slot will be used as an index and the sprite will be used as an icon.

    My questions are

    1. Is it possible to make an array (not the construct 2 array, but a javascript array/list) of these "items" that I'm creating?
    2. Is it possible to make an 'expression' that allows users to access each item with a line such as "Player.Inventory.Item(1)"?
    3. Is it possible to make sure that the object that users select for the icon is only a sprite object?

    I can post my edittime/runtime with a .capx example if you want.

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • I don't think it's possible to set an expression return type as an object. The only supported return type for "any" is ef_return_any and that only supports int, float and string (according to the documentation.

    However, you can maybe have the expression return an object UID and then use the "Pick by UID" event to return the correct object.

    As for checking the object type. In the expression, you can do a lookup on the UID to find the object type and then you can do an "instanceof cr.plugins_.Sprite" comparison. If that fails you can throw an exception.

  • Okay, thanks for the reply. I'll give those suggestions a shot.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)