Using objects "by name"

Post » Mon Feb 13, 2017 1:26 pm

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.
B
8
S
2
Posts: 56
Reputation: 1,021

Post » Mon Feb 13, 2017 1:31 pm

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.
Scirra Founder
B
399
S
236
G
89
Posts: 24,543
Reputation: 195,430

Post » Mon Feb 13, 2017 3:13 pm

Ashley wrote: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.

Ashley wrote: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.

Ashley wrote: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? :)
B
8
S
2
Posts: 56
Reputation: 1,021

Post » Mon Feb 13, 2017 3:43 pm

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.
Image ImageImage
B
171
S
50
G
180
Posts: 8,394
Reputation: 113,982

Post » Mon Feb 13, 2017 3:46 pm

Yozzik"[quote="Ashley wrote: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.
[/quote]
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.
Scirra Founder
B
399
S
236
G
89
Posts: 24,543
Reputation: 195,430

Post » Mon Feb 13, 2017 9:08 pm

I could be wrong, but this functionality sounds like Rex's Nickname plugin.(http://c2rexplugins.weebly.com/rex_nickname.html)
B
42
S
12
G
1
Posts: 74
Reputation: 2,992


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest