Feature request: using expressions to initialise variables

Discussion and feedback on Construct 2

Post » Tue Dec 30, 2014 5:05 pm

Hi !

I don't think this is currently possible, so I'd like to suggest a feature to let us initialise variables (local and global) with expressions, instead of "pure" number values. A variable would take the value of the expression when the expression is evaluated when entering the scope of the declaration.

When writing custom behaviours for movement, clipping, etc. I find it easier to use local variables to keep the events readable and maintainable, esp. for temporary values that are used in multiple computations. There are lots of formulas using "sprite size" +/- various offsets +/- arbitrary numbers +/- scaling factors, and it's much quicker to write the expression just once.

At the moment I find myself writing a few :
Code: Select all
local number foo = 0
(empty) System > set foo to "exression"

Which is a bit clunky ; it would be much better to be able to specify the expression directly as the initial value for the scope of the variable. Also, this prevents me from setting the variables as "constant", which again would help with readability and maintainability.

If there's a better way, let me know, otherwise I believe it would be a great addition.

Thanks for reading
Image
Game Producer & Independent Developer - http://raphaelgervaise.com
B
24
S
9
Posts: 237
Reputation: 2,232

Post » Tue Dec 30, 2014 9:21 pm

For the use of repetitive formulas/events I would use functions.
Who dares wins
B
57
S
17
G
21
Posts: 1,878
Reputation: 19,572

Post » Tue Dec 30, 2014 9:27 pm

+1 this and also to be able to do it in object Properties. If I define constants like CONST1 = 1, CONST2 = 2, etc. I still have to put 1, 2, etc. in the 'initial value' which defeats some of the purpose and is error prone.
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Dec 31, 2014 8:51 am

Functions are definitely a possible alternative or work-around using the existing features of C2. Though using them only for breaking down formulas or re-using bits of computations multiple times, I think they're a bit overkill, especially when there's no parameter or actual logic involved.

'Just a small suggestion to help keep things neat and tidy :)

also to be able to do it in object Properties


Indeed ; it would be very convenient to have this on global/local variables but also member data on objects !
Image
Game Producer & Independent Developer - http://raphaelgervaise.com
B
24
S
9
Posts: 237
Reputation: 2,232


Return to Construct 2 General

Who is online

Users browsing this forum: boybacteria, MadSpy, TheRealDannyyy and 16 guests