# math trick needed

Get help using Construct 2

### » Fri Oct 13, 2017 7:52 am

Hi my project have text object to display sum of variables
Global variable called 'percent'

Player sprite have two instance variables:
Strenght physical 'SP'
Strenghth mental 'SM'

NEXT

Text object should display global variable 'percent' (SP + SM in percents %)

Important thing
when SP is X and SM is X
on start of layout Text object should display this sum as 100%
B
25
S
8
Posts: 219
Reputation: 2,181

### » Fri Oct 13, 2017 8:27 am

On start:
set percent to int(100*(SP+SM)/(2*X))
set text to percent&"%"

On any trigger event where SP or SM change:
set percent to int(100*(SP+SM)/(2*X))
set text to percent&"%"

This assumes that X is the maximum value that SP and SM can have.
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

### » Fri Oct 13, 2017 9:56 am

mekonbekon wrote:On start:
set percent to int(100*(SP+SM)/(2*X))

What is 'X' in your formula?
(2*X)) ?
B
25
S
8
Posts: 219
Reputation: 2,181

### » Fri Oct 13, 2017 11:05 am

@IGDev

X is the maximum value of SP and SM e.g.

If SP and SM can each have a maximum value of 150 each then the equation would be:

int(100*(SP+SM)/300)

ideally you would hold those max values in variables, so the equation would be:

int(100*(SP+SM)/(SPmax+SMmax))
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

### » Fri Oct 13, 2017 11:18 am

mekonbekon wrote:@IGDev

X is the maximum value of SP and SM e.g.

If SP and SM can each have a maximum value of 150 each then the equation would be:

int(100*(SP+SM)/300)

ideally you would hold those max values in variables, so the equation would be:

int(100*(SP+SM)/(SPmax+SMmax))

Text object show me on preview
'Infinity %'
B
25
S
8
Posts: 219
Reputation: 2,181

### » Sat Oct 14, 2017 1:35 pm

@IGDev

Here's an example:

https://www.dropbox.com/s/ss9xlbwj1rmqv ... .capx?dl=0

Left or right click on the bars to change the values.
B
22
S
9
G
4
Posts: 476
Reputation: 4,327

Return to How do I....?

### Who is online

Users browsing this forum: dop2000, plinkie, Seruza, Yahoo [Bot] and 8 guests