How to form formulas

This forum is currently in read-only mode.
0 favourites
  • Yep. No need for fear, tho - copy and paste the code, toggle the copied event off (in the ribbon under events) and you can mess with the code without worrying about messing up what you had.

  • another problems... aparently i am a good friend of them.

    i want var ShieldsCurrent value to be downgraded to ShieldsTotal value. so you know, whenever it goes over ShieldsTotal var value it is fixed down. now what did i screwed up this time?

    <img src="http://img340.imageshack.us/img340/15/32293546.png">

    EDIT:

    and my second problem. i never been good in math but i have even more problem forming a proper expression chain.

    basicly what i want:

    i want "Something X" to happend when Value of var "EnergyCurrent" is at 50% of value of var "EnergyTotal".

    how should i form it in conditions?

    i know "IF variable "EnergyCurrent" is Equal or Lower... what now?

    50 % global('EnergyTotal')[/code:x2xlir3c]...? is that correct
    
    EDIT2: adding to my last question what formula i should use when value X is LOWER then 90% but HIGHER then 50%?
  • bumpy bumper bump.

  • % does not give you percent, it gives you the remainder after division.

    http://sourceforge.net/apps/mediawiki/construct/index.php?title=Expressions

    To get 50% of a value just multiply by 0.5.

  • [quote:1pwehmyb]To get 50% of a value just multiply by 0.5.

    now i feel like an retard lol. damn you elementary math!

    Thank you R0J0hound!

    so the condition would be IF global('ShieldsTotal') & = & (global('ShieldsTotal') & * & 0.5) ?

    even so - i still dont know how to form a range of values (e.g all betwen 40 and 70)

    and obviously i still havent figured out how to make a variable change its value to another variable value. if i use

    IF variable X = or > then variable Y

    then

    set variable X equal variable Y

    hell breaks loss and both variables becomes linked togather - so if i change any of them the second follows.

  • Take it easy. It'll come

    Ampersand (&) is for strings(text), so that's really not where you want to go here.

    There's another page you might want to take a look at: system expressions.

    http://sourceforge.net/apps/mediawiki/construct/index.php?title=System_Expressions

    If you look there you'll find clamp:

    [quote:1xcn8spr]Clamp(Value, Lower bound, Upper bound)

    Returns Value if it is between Lower bound and Upper bound. Returns Lower bound if Value is less than Lower bound. Returns Upper bound if Value is greater than Upper bound

    So...

    clamp(variable,40,70)

  • [quote:37w7yvur]i want var ShieldsCurrent value to be downgraded to ShieldsTotal value. so you know, whenever it goes over ShieldsTotal var value it is fixed down.

    In that case, it's always better to simply not allow that to happen. You can either test it first, then only set it if it will remain valid, or clamp it's value while setting it.

    I made a simple example .cap (with Construct v0.99.96) that shows a bit of dealing with percentages, clamping values, and testing for ranges.

    http://dl.dropbox.com/u/5868916/irbis1.cap

    Good luck.

  • Take it easy. It'll come

    Ampersand (&) is for strings(text), so that's really not where you want to go here.

    There's another page you might want to take a look at: system expressions.

    http://sourceforge.net/apps/mediawiki/construct/index.php?title=System_Expressions

    If you look there you'll find clamp:

    [quote:3ffo3wza]Clamp(Value, Lower bound, Upper bound)

    Returns Value if it is between Lower bound and Upper bound. Returns Lower bound if Value is less than Lower bound. Returns Upper bound if Value is greater than Upper bound

    So...

    clamp(variable,40,70)

    ih man i knew this most be something obvious right in front of my nose!

    Thank yiu for that link Newt. i did check the "espressions" page, didnt figure out theres another diffrent one hah

    now - many things became so simple

    [quote:3ffo3wza]In that case, it's always better to simply not allow that to happen.

    thats the problem. if the would be just couple of conditions that changes this var i would just turn them off by auto with conditions, but the problem is - theres lots of conndtidions that changes this one and its an ant-job to add off switch for all of them or even keep track of them.

    thank you very much for the cap mate

    EDIT:

    okey guys it seems i screwed up once again

    whats wrong with this?

    clamp(global('Spaceship - EnergyTotal'),global('Spaceship - EnergyTotal')*0.6,global('Spaceship - EnergyTotal')*0.69)[/code:3ffo3wza]
    
    <img src="http://img829.imageshack.us/img829/908/shit0.png">
  • I think your over complicating things. Try getting rid of the Else's and put every condition as a separate condition.

    If that works, then you can go back and try to simplify it more.

  • I think your over complicating things. Try getting rid of the Else's and put every condition as a separate condition.

    If that works, then you can go back and try to simplify it more.

    done and ready. still not working.

    New issue #1:

    another weird thing that i have just discovered is weird effect of "every X milisec's" contidion.

    for value regeneration i use plain "Each X miliseconds" conditions and offten my values are like 1.20 0.80 3.33 ect. my problem is on example of Shields Regeneration. it starts with

    0 value with 1.20 regen rate and goes all the way to 38 and then BLAM 40.7999999999999, and becomes even more and more messed up with each second. now how 1.2 value multiplyd by any round number can become 40.7999999999999??? O.o

    i know that i can fix at last the shown value by adding round() around the var but its just like pushing trash under the carpet instead of cleaning it.

    new Issue #2:

    Bonuses/buffs. in many games you have those. like a ring of power +9 to str, magic shield +10 to AC, skill that grants you a passive +10% to all dmg.

    now how can i do this in Construct? what sort of conditions i should use? the only i can think of is hell of a work to make the Total value be (var value + value bonuses) and opening another var names bonuses and then enlisting ALL kinds of bonuses i can have.

    on example of my game. i have variable EnergyTotal that is being set by the Reactor Function. but would like to also have like batteries, special perks, rare awards that add passive values to var EnergyTotal. and there would be no problem IF i would have just one type of reactor. i would just use var add value. but i have many types of reactors and i want the EnergyTotal value be always updated with the bonuses. like for example:

    Reactor 1 with TotalValue 100 and a bonus +15 to TotalValue. so the total value is 115.

    now i change Reactor 1 for a better one Reactor 2 which has value 200. so i want that bonus to be added as the last and combine with other bonuses. otherwise the previous TotalValue of ReactorValue + Bonus 1 will be overwrite with just the total value set by new Reactor 2, so instead of 215 ill get 200.

    any ideas?

  • whats wrong with this?

    clamp(global('Spaceship - EnergyTotal'),global('Spaceship - EnergyTotal')*0.6,global('Spaceship - EnergyTotal')*0.69)[/code:1v2oqfvx]
    

    There's nothing wrong with it. It just doesn't make sense. The returned value of this expression will always conform to global('Spaceship - EnergyTotal') * 0.69.

    clamp returns a bounded value. But, if you make the bounds relative to the value, it will always return the highest or lowest value, depending on the relation. Just replace global('Spaceship - EnergyTotal') with a value to see the problem. Let's say, global('Spaceship - EnergyTotal') equals 100:

    clamp(100,100*0.6,100*0.69)

    You're now ordering Construct to return 60, if the original value is lower than 60, to return the original number, if it is between 60 and 69, and to return 69, if the original value is greater than 69. But the original value always is 100, and so you are always getting 69.

    And now think of all the different values, global('Spaceship - EnergyTotal') may have. They all will be greater than global('Spaceship - EnergyTotal') * 0.69

    clamp(50,50*0.6,50*0.69) will return 34.5 (always and only)

    clamp(260,260*0.6,260*0.69) will return 179.4 (always and only)

    So, if you are comparing global('Spaceship - EnergyCurrent') with clamp(global('Spaceship - EnergyTotal'),global('Spaceship - EnergyTotal')*0.6,global('Spaceship - EnergyTotal')*0.69), you are comparing global('Spaceship - EnergyCurrent') with global('Spaceship - EnergyTotal')*0.69

    This comparison will only be successful, if global('Spaceship - EnergyCurrent') conforms exactly to global('Spaceship - EnergyTotal')*0.69, and not to a range of values.

    Don't make the bounds of clamp relative to its value. And, if you want global('Spaceship - EnergyCurrent') to be in a certain range for the condition to become true, do this:

    + Is global variable 'Spaceship - EnergyCurrent' greater or equal global('Spaceship - EnergyTotal') * 0.6
      Is global variable 'Spaceship - EnergyCurrent' less or equal global('Spaceship - EnergyTotal') * 0.69
    [/code:1v2oqfvx]
    That's two conditions in one event, meaning they both need to be true for the action to be performed. And they are both true for [i]every[/i] value between global('Spaceship - EnergyTotal') * 0.6 and global('Spaceship - EnergyTotal') * 0.69
  • hmmm. somethings wrong but i dont know what. now it works partialy. so when Current = Total it displays the 100% value but stays at it and doesnt change.

    i triple checked the animation, its setting, constrollers, variables and all is okey.

    from what i have traced - for some reason ONLY the first condition

    IF global('Spaceship - EnergyTotal') * 1[/code:1cq7u4wl]
    is being exectuded. the rest is just ignored. 
    
    sample of the rest:
    <img src="http://img84.imageshack.us/img84/8453/14403168.png">
    
    so i presume they are to blame
  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • It seems, you want to present some kind of a shield status display. This display has 11 frames, representing 11 states of the shield status. Something like this:

    xxxxxxxxxx -> shield 100%

    xxxxxooooo -> shield 50%

    oooooooooo -> shield 0%

    Am I right? If so, there is a much simpler way achieving this. You have two values, EnergyTotal and EnergyCurrent. The first one is a value depending on the ship and its equipment. It may be 300 for one ship and 500 for another. If it was 300, then EnergyCurrent would have a start value of 300 and then lower whenever energy is used. And if EnergyCurrent is 150 it is 50% of EnergyTotal. But if the player now enhances the ship, the EnergyTotal may raise to 500. In result the 150 of EnergyCurrent represent no longer 50%, but 30%.

    If all of these assumptions are right, then you only need to do the following:

    + Always
    -> EjectorShieldBar: Set animation frame to int((EjectorShieldBar.GetAnimationFrameCount - 1) / global('Spaceship - EnergyTotal') * global('Spaceship - EnergyCurrent')) + 1[/code:1fpmigt2]
    
    Yes, you only need one event for all of your animation frames. The expression
    
    int((EjectorShieldBar.GetAnimationFrameCount - 1) / global('Spaceship - EnergyTotal') * global('Spaceship - EnergyCurrent')) + 1
    
    automatically sets the right frame in relation to the percentage from EnergyCurrent to EnergyTotal.
    
    [h2]EnergyTotal = 300
    EnergyCurrent = 300
    EjectorShieldBar.GetAnimationFrameCount = 11
    --> frame = int((11 - 1) / 300 * 300) + 1 = int(10 / 300 * 300) + 1 = 10 + 1 = 11
    
    EnergyTotal = 300
    EnergyCurrent = 0
    EjectorShieldBar.GetAnimationFrameCount = 11
    --> frame = int((11 - 1) / 300 * 0) + 1 = int(10 / 300 * 0) + 1 = 0 + 1 = 1
    
    EnergyTotal = 300
    EnergyCurrent = 150
    EjectorShieldBar.GetAnimationFrameCount = 11
    --> frame = int((11 - 1) / 300 * 150) + 1 = int(10 / 300 * 150) + 1 = 5 + 1 = 6
    
    EnergyTotal = 500
    EnergyCurrent = 150
    EjectorShieldBar.GetAnimationFrameCount = 11
    --> frame = int((11 - 1) / 500 * 150) + 1 = int(10 / 500 * 150) + 1 = 3 + 1 = 4
    
    EnergyTotal = 500
    EnergyCurrent = 150
    EjectorShieldBar.GetAnimationFrameCount = 21
    --> frame = int((21 - 1) / 500 * 150) + 1 = int(20 / 500 * 150) + 1 = 6 + 1 = 7[/h2]
    
    You may change every value (including the number of frames you use in your animation to represent the status), it will always show the correct status of the ships shield.
  • another weird thing that i have just discovered is weird effect of "every X milisec's" contidion.

    for value regeneration i use plain "Each X miliseconds" conditions and offten my values are like 1.20 0.80 3.33 ect. my problem is on example of Shields Regeneration. it starts with

    0 value with 1.20 regen rate and goes all the way to 38 and then BLAM 40.7999999999999, and becomes even more and more messed up with each second. now how 1.2 value multiplyd by any round number can become 40.7999999999999??? O.o

    That's because of rounding errors - floating point numbers like 1.2 can't be counted on to be calculated exactly. It's a limitation of processors. If you want exact numbers, stick to integers (whole numbers without decimals like 1).

  • thats wicked.

    and it almost works. and i dont know why.

    the problem is, last frame suppose to be 100% ShieldEnergy only, just the first frame 0% should be displayed only when ShieldsCurrent hits 0%. with this the last frame 100% is for some reason never played, or should i say - it is but if ShieldCurrent is about 100% (100,000001% for example).

    so anyway, two questions:

    why my method doesnt work and why your does.

    also - what the heck is int expression??? i never seen that before on both expresions and system expresions pages on wiki.

    and well... many my previous issues are left unasweared

    [quote:3th6hoph]That's because of rounding errors - floating point numbers like 1.2 can't be counted on to be calculated exactly. It's a limitation of processors. If you want exact numbers, stick to integers (whole numbers without decimals like 1).

    wow. everyday i learn something new. never knew about such thing. how weird is that O.o like - it can easly count 2 + 2 but have troubles with 0,2 + 0,2?

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