Why can't I name animations numbers (like "1")? Workarounds?

Get help using Construct 2

Post » Thu Feb 12, 2015 12:01 pm

Hello people.

Problem: I am not allowed to name an animation a simple number such as "1" or "34". It just reverts the name back to the previous one with no error message or reason why it doesn't work. I don't know if this is a bug or intended, I guess intended to stop certain stuff?

I want to spawn random background objects in my side scrolling game. The way I have been doing this is using tons of events and sprites each individually looking something like "if level = 1, Every random(3,6) seconds create object cloud1" etc...

Now I would like to make a big "BGobjects" sprite that contains tons of animations and frames for the various BG objects I need. I can simply name each animation 1 2 3 4... for each level they go into and do then the following:

Every random(3,6) seconds create object BGobjects

set BGobjects animation frame to Level (So on level 1, it will be all the level 1 objects, level 2 they'll all be level 2...)

set BGObject frame to choose (1,2,3,4) for the 4 different kinds of clouds that fit into level 1. Or the 4 different kinds of bubbles that fit the underwater level 2. Etc.

This would work seamlessly and use very few events, if only it allowed me to name the animations simple numbers in the first place...

The only theoretical workaround I can think of but have not tried yet is to simply call the animations fitting names such as "Clouds" "Bubbles" and then simply add a global variable called "AnimationHelper" and 4 events like (Level = 1, set AnimationHelper to "Clouds") (Level = 2, set AnimationHelper to "Bubbles")

And then just

set BGobjects animation frame to AnimationHelper

Same thing but a little more convoluted, should work though, right? Any better ideas? Any explanation on why I'm unable to name an animation a number? Thanks.
B
4
Posts: 22
Reputation: 244

Post » Thu Feb 12, 2015 12:10 pm

Or you could add something to make the name longer, like "Animation1" "Animation2" "Animation3" and then just do a Set animation to "Animation" & AnimationNumber <== Your variable sort of thing.

The problem with "short" names I think lies not in shortness, but in it being a number.
B
19
S
6
G
6
Posts: 1,101
Reputation: 5,646

Post » Thu Feb 12, 2015 12:48 pm

You generally can't name things with a number, because it makes it ambiguous whether a name is a name or a number. The best example is with object type names, where they can appear in expressions e.g.

Sprite.X

If you could call a sprite "34" then it appears as

34.X

which is difficult for the parser to figure out what you mean (since 34. is a valid floating point number). That doesn't exactly apply to animations, but for consistency and future-proofing the same principle is applied nearly everywhere. Workaround: use names like "a1", "a2", "a3"... and set the name "a" & number.
Scirra Founder
B
367
S
217
G
82
Posts: 23,262
Reputation: 183,679

Post » Thu Feb 12, 2015 12:49 pm

Thanks for both of your responses, you've cleared it up and gave a better compromise than the one I came up with.

Cheers!
B
4
Posts: 22
Reputation: 244


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 3 guests