Results 1 to 5 of 5

Thread: Keep a percent <=100

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Feb 2000
    Posts
    18
    I made a game that has a health thing that if something bad happens then percentage is deducted but when when something good happens then percentage is added. But the problem is that the pecentage is going over 100 and I want it to stay 100 or under how do I do that. The health variable is named inthealth <-- its an Integer

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    You can change the inthealt var to a property get/let var:

    Dim inthealthProp ' and let this be the real one

    Property get inthealth ()
    inthealth=inthealthProp
    end property
    Property let inhealth(newval)
    inthealthProp=newval
    if inthealthProp>100 then inthealthProp=100
    end property

    Hope this helps

  3. #3
    Hyperactive Member Al Smith's Avatar
    Join Date
    May 1999
    Location
    Marcellus, MI. USA
    Posts
    330

    Will this work for you?

    Hi,
    If you're adding points for good_health and bad_health then the formula:

    ((good_health - bad_health) / good_health) * 100

    will never be above 100% unless bad_health goes negative, at which time I would guess you're dead.

    Al.

  4. #4
    Lively Member
    Join Date
    Jun 1999
    Posts
    120

    when adding the health earned to the intHealth, just use the
    line below or something like this:

    intHealth = IIF(intHealth + plusHealth > 100, 100, intHealth + plusHealth)

    hope this helps...

  5. #5
    Lively Member
    Join Date
    Jul 1999
    Posts
    99
    if iCurrentHealthPoints > iMaxHealthPoints then
    iCurrentHealthPoints = iMaxHealthPoints
    End if
    iHealth = (iCurrentHealthPoints / iMaxHealthPoints) * 100

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width