Using objects "by name"

0 favourites
  • 6 posts
From the Asset Store
With this template you will learn how to use the GooglePlay Games native plugin
  • I've been talking about this on forum for a few years from time to time - hope in C3 discussions it has more chances.

    Since we can refer to audiofiles "by name" (like "Play (by name)"), can we create objects by name and refer to them?

    Like instead of well known "click to choose" we will have a field to enter object's name.

    Such a flexible logic can be really handy in many situations like:

    1. When you use array or CSV to store data about units and spawn them. For sure, i can spawn a sprite named "Unit", refer to it's animation to define unit type\graphics and then do a ton of actions to set some specific parameters (movement speed, HP, damage, etc.). But hell i could predefine them in different objects and then just spawn.

    2. When you have a lot of objects on the scene and on touch you react in specific ways (like get damage from subject). For sure, i can hardcode every case (a ton of similar events) or somehow use the family. But hell i could just do 1 abstract action like set player.HP to self.HP - subject.damage or even self.HP - touch.subject.damage.

    Overall, it would be really cool to have more abstraction in events so we can save time and do more simple-looking code.

  • This has been regularly suggested for C2 for a while now, but my main concerns are:

    1) lots of users are worried about their projects getting reverse-engineered, and to make this harder currently we strip out all object names from the project. To support this, we'd need to add them back in.

    2) this would add ambiguous results to the just-announced find all references feature. If you create an object from a string in a CSV file, for example, C3 can't know for sure if that will or won't reference a particular object. So most likely it will have to add that "create by name" result in to every "find references" result list - or never add it. Either way, it makes the feature less useful.

    It's also relatively straightforward to work around in events (e.g. using a function call) without affecting either of those points.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 1) lots of users are worried about their projects getting reverse-engineered, and to make this harder currently we strip out all object names from the project. To support this, we'd need to add them back in.

    I have no position here (don't really care), so ok, 1:0, this seems really serious.

    2) this would add ambiguous results to the just-announced find all references feature ... so most likely it will have to add that "create by name" result in to every "find references" result list - or never add it. Either way, it makes the feature less useful.

    But why? Obviously, if i'm interested in "Unit" object, i have to see event\action that spawns it.

    It's also relatively straightforward to work around in events (e.g. using a function call) without affecting either of those points.

    Like call function "Unit" with f.param(0) = "spawn" and f.param(1) = "archer" or "ranger", and then you have to do a bunch of similar actions twice?

  • Creating a variable and using it to pick using an instance variable comparison is a simple method.

    You can name the value anything you like.

  • 2) this would add ambiguous results to the just-announced find all references feature ... so most likely it will have to add that "create by name" result in to every "find references" result list - or never add it. Either way, it makes the feature less useful.

    But why? Obviously, if i'm interested in "Unit" object, i have to see event\action that spawns it.

    The editor doesn't know what the values will be at runtime. Another example is letting the user type in a name, and creating something based off that. The editor can't possibly anticipate what the results will be, so it has to either always show the unknown cases, or never show them.

  • I could be wrong, but this functionality sounds like Rex's Nickname plugin.(http://c2rexplugins.weebly.com/rex_nickname.html)

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