Convert Variable Values

  • I'm having a bit of trouble wrapping my head around something.

    I'm struggling to control variables, here's an example:

    Say if I have a number variable called speed, it starts at 0. If the player presses up, every tick add 1 to 'speed' - if player releases up, every tick subtract 1 from speed.

    First question is how do I 'clamp' the variable so that it never extends past a max or minimum speed?

    Second question is how would I use this 'speed' variable to affect something else which uses a different numerical range, let's say volume, at 0 speed, volume should be 0db at 50 speed volume should be 0.5 etc

    I know how to set 'volume' to 'speed' - but I don't want the volume to have a range of 0 - 100, I'd like it to be 0 - 1 - or even if it was something wild like timescale, I'd like timescale to be affected by 'speed' but with a range of 0 - 1.5 instead of 0 - 100.

    Am I explaining this okay? I'm pretty confused over the matter haha.

    Best,

    Mik

  • System expressions are what you're looking for question 1.

    The clamp() expression is listed in the category "Values" in the expressions dialog.

    For question 2 it looks like a ratio where you would divide the first value by 10 (or 100 ?) to get value 2.

    Also you should have a read at delta time and framerate independence and rethink your design (don't add a "fixed" 1 every tick, you'll have different executions on differently powered CPUs).

    Example capx.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks man very useful!

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