Returning an Object/Array Expression?

For developers using the Construct 2 Javascript SDK

Post » Fri Oct 25, 2013 5:03 pm

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.SirH3nry2013-10-25 17:07:43
B
2
Posts: 3
Reputation: 181

Post » Sat Oct 26, 2013 12:26 pm

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.
B
3
Posts: 6
Reputation: 187

Post » Sun Oct 27, 2013 3:49 pm

Okay, thanks for the reply. I'll give those suggestions a shot.
B
2
Posts: 3
Reputation: 181


Return to Javascript SDK

Who is online

Users browsing this forum: No registered users and 1 guest