Expression Need to help with one calculation

Get help using Construct 2

Post » Sat Apr 08, 2017 7:10 am

I have 3 global variables:
Acurrent
Bincome
Cmax

Global variable "Acurrent" have 300
Global variable "Cmax" have 500
Global variable "Bincome" will be have random number lets for example set to 400

now when i click button

system should fill "Cmax" to his maximum variable (500)

Add "Bincome" (400) to "Acurrent"(300)
BUT when "Acurrent" is 300 we can add only 200 from "Bincome"

so finally after clicking button
we should have calculation
A-500
C-500
B-200


SECOND EXAMPLE
when Cmax have only 50
and Acurrent have 0

We take from Bincome only 50
B
24
S
7
Posts: 208
Reputation: 2,032

Post » Sat Apr 08, 2017 11:21 am

@IGDev

Add another variable to as a placeholder for the income to add, then do:

Set tempToAdd to Acurrent + Bincome > Cmax ? Cmax - Acurrent : Bincome

Set Acurrent to Acurrent + tempToAdd

Set Bincome to Bincome - tempToAdd
Vote for all the Construct 2 games on Steam Greenlight - Find them here
B
32
S
9
G
7
Posts: 444
Reputation: 6,731

Post » Sat Apr 08, 2017 11:30 am

(Cmax - Acurrent) = MaxFill

If Bincome > MaxFill
. .... then NewAcurrent = Acurrent - MaxFill
& NewBincome = Bincome - MaxFill

If Bincome <= MaxFill
. ... then NewAcurrent = Acurrent - Bincome & NewBincome = zero

Or getting MaxFill out there again (it explained well with)

If Bincome > (Cmax - Acurrent)
. .... then NewAcurrent = Acurrent - (Cmax - Acurrent)
& NewBincome = Bincome - (Cmax - Acurrent)

If Bincome <= (Cmax - Acurrent)
. ... then NewAcurrent = Acurrent - Bincome
& NewBincome = zero

Under the assumption that Bincome cant be negative.
B
33
S
18
G
28
Posts: 2,455
Reputation: 20,874

Post » Sat Apr 08, 2017 11:42 am

No, that is wrong, i suppose Acurrent cant be less than zero too.
B
33
S
18
G
28
Posts: 2,455
Reputation: 20,874

Post » Sat Apr 08, 2017 12:07 pm

99Instances2Go wrote:No, that is wrong, i suppose Acurrent cant be less than zero too.

im so confused about this

can you show this in capx?
B
24
S
7
Posts: 208
Reputation: 2,032

Post » Sat Apr 08, 2017 12:13 pm

If all you care for is capping your Acurrent variable just go:

Set Acurrent to
Bincome+Acurrent>Cmax?Cmax:Bincome+Acurrent


If you really need Bincome changed upen exceeding that threshold

set Bincome to
Bincome+Acurrent>Cmax?Cmax-Acurrent:Bincome+Acurrent

Then you can add Acurrent and Bincome
B
12
S
5
Posts: 207
Reputation: 1,672

Post » Sat Apr 08, 2017 12:24 pm

Haha, you quoted me, now i cant erase my stupid comments. Here goes :

Legal maximum for Acurrent = Cmax

Possible illegal maximum >> Bincome + Acurrent = bigger then Cmax
Everything bigger then Cmax goes back to Bincome

So .....

Local variable temp

temp = min(Bincome + Acurrent,Cmax)
Bincome = (Bincome + Acurrent) - temp
Acurrent = temp

https://www.dropbox.com/s/yajxehyx8sxre ... .capx?dl=0
B
33
S
18
G
28
Posts: 2,455
Reputation: 20,874

Post » Sat Apr 08, 2017 1:15 pm

99Instances2Go wrote:Haha, you quoted me, now i cant erase my stupid comments. Here goes :

Legal maximum for Acurrent = Cmax

Possible illegal maximum >> Bincome + Acurrent = bigger then Cmax
Everything bigger then Cmax goes back to Bincome

So .....

Local variable temp

temp = min(Bincome + Acurrent,Cmax)
Bincome = (Bincome + Acurrent) - temp
Acurrent = temp

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



i see now what is missing

when i calculate first time
From B 200 goes to A abd 200 stay

its possible to make this without Textboxes?


For example when my A is equal to C
A should be changed to 0

and i we should have posibility to click again and add rest from B to A variable?
B
24
S
7
Posts: 208
Reputation: 2,032


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 13 guests