Expression Need to help with one calculation

0 favourites
  • 8 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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

  • (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.

  • No, that is wrong, i suppose Acurrent cant be less than zero too.

  • No, that is wrong, i suppose Acurrent cant be less than zero too.

    im so confused about this

    can you show this in capx?

  • 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

  • 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

  • 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?

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