math trick needed

Get help using Construct 2

Post » 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: 215
Reputation: 2,173

Post » 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
20
S
8
G
3
Posts: 457
Reputation: 4,053

Post » 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)) ?
Image
B
25
S
8
Posts: 215
Reputation: 2,173

Post » 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
20
S
8
G
3
Posts: 457
Reputation: 4,053

Post » 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))

Image

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

Post » 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
20
S
8
G
3
Posts: 457
Reputation: 4,053


Return to How do I....?

Who is online

Users browsing this forum: Norafaithrainbow and 30 guests