Feature request: using expressions to initialise variables

0 favourites
  • 4 posts
From the Asset Store
Easily store, modify, read and manipulate colors with Color Variables!
  • 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 :

    local number foo = 0
    (empty) System > set foo to "exression"[/code:kjk7jnxa]
    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
  • For the use of repetitive formulas/events I would use functions.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • +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.

  • 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

    [quote:3fc6xn1c]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 !

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