Convert Variable Values

Get help using Construct 2

Post » Mon Feb 18, 2013 12:28 pm

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


B
39
S
12
G
8
Posts: 580
Reputation: 7,108

Post » Mon Feb 18, 2013 1:17 pm

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.
Kyatric2013-02-18 13:18:35
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 7,000
Reputation: 57,795

Post » Mon Feb 18, 2013 1:23 pm

Thanks man very useful!
B
39
S
12
G
8
Posts: 580
Reputation: 7,108


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 25 guests