How do I Return An Object Name

Get help using Construct 2

Post » Thu Oct 09, 2014 10:39 am

What I'm trying to do:
Code: Select all
sprite.click() {
textBox.text = this.objectName
}

I can see there's a .layerName expression but I can't find anything along the lines of .objectName or .spriteName - is there a way to automatically set the instance variable to the object name instead? Setting them manually isn't an option due to the vast number.

Thanks.
AVA ROWELL - simplisto.com - @avarowell - add me (simplisto) on Steam!
B
8
S
2
Posts: 23
Reputation: 1,138

Post » Thu Oct 09, 2014 10:58 am

you could do it like this
You do not have the required permissions to view the files attached to this post.
B
249
S
39
G
15
Posts: 1,952
Reputation: 40,596

Post » Thu Oct 09, 2014 11:26 am

Thanks for the capx - but did you change the animation names manually?
AVA ROWELL - simplisto.com - @avarowell - add me (simplisto) on Steam!
B
8
S
2
Posts: 23
Reputation: 1,138

Post » Thu Oct 09, 2014 1:41 pm

What you do is go into Animation Editor and on right side there is box where you can type animation. Type name here or open my capx and double click blue or green box. This should help you because by name of animation name is Default. Just type your chosen name
B
249
S
39
G
15
Posts: 1,952
Reputation: 40,596

Post » Thu Oct 09, 2014 2:54 pm

Unfortunately, I have too many sprites to set manually, which is why I need a way to retrieve the object names.
AVA ROWELL - simplisto.com - @avarowell - add me (simplisto) on Steam!
B
8
S
2
Posts: 23
Reputation: 1,138

Post » Thu Oct 09, 2014 3:32 pm

Yes but every sprite has animation is it not? Even every time you add sprite you import the IMAGES yes?
B
249
S
39
G
15
Posts: 1,952
Reputation: 40,596

Post » Thu Oct 09, 2014 3:53 pm

The default animation name for each added sprite will always be 'default' though.

There are many ways I can manually tag each sprite individually - I'm asking if there's a means to avoid this.
AVA ROWELL - simplisto.com - @avarowell - add me (simplisto) on Steam!
B
8
S
2
Posts: 23
Reputation: 1,138

Post » Thu Oct 09, 2014 5:03 pm

I always wondered why there wasn't any mean to retrieve the type name at runtime. It's not like the variable isn't there...

Using the Browser object's ExecJS expression, you can easily retrieve it though, it's just unconvenient.
You do not have the required permissions to view the files attached to this post.
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Post » Thu Oct 09, 2014 5:43 pm

@Magistross It wouldn't work after export though would it?

I think the reason you can't get the object name is because they are obfuscated at export. Same reason we can't create an object by name.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Thu Oct 09, 2014 5:47 pm

@ramones It certainly won't work after obfuscating. It would still work though if we created a behavior with the sole purpose of providing an expression to retrieve the instance type name. Variable names get obfuscated, but string literals doesn't.
B
69
S
28
G
24
Posts: 977
Reputation: 18,739

Next

Return to How do I....?

Who is online

Users browsing this forum: dop2000, namaewayukidesu, Yahoo [Bot] and 9 guests