Re: health regenerating code

Get help using Construct 2

Post » Wed Jan 08, 2014 11:41 am

Hi,

I have been using construct 2 trial for a couple months now. Making small game examples as a hobby.

I recently stumble on this problem and would appreciate it if someone could help me. Note, I do not have enough rep... so no capx.

This is what i have.

Global number Healing = 0
Global number Hp = 0
Global Number MaxHp = 5000
----------------------------------
Mouse
|left button is down|
System Heal > 0
Hp < Max Hp
           system| add 1 + 1 * int((MaxHp -HP/10) to HP
           system| Subtract 1 + 1 * int((MaxHp -HP/10) from Healing
------------------------------------
Problem: Works fine if healing is same or more than Max.Hp, but it goes down to negative if healing is less than maxhp.

Well, I am pretty sure that the problem is (1 * int((text.MaxHp -HP/10) to HP) as it just do a deduction base on the number it get from there.

Any help or pointers would much be appreciated...Eastcr9w2014-01-08 23:52:18
B
8
S
2
Posts: 6
Reputation: 776

Post » Wed Jan 08, 2014 11:55 am

could you please try to explai what it is you are trying to do there?

What is this line supposed to achieve?

add 1 + 1 * int((text.MaxHp -HP/10) to HP

text.maxHp, so MaxHp is an instance variable of the text?
Why not use a global variable MaxHp?
Why HP/10?

If I understand what you are trying to do, it will probably be easier to see where you go wrong.


LittleStain2014-01-08 12:02:06
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Wed Jan 08, 2014 1:27 pm

Ah, I am sorry. I forgot to explain...

I want to make a healing ability with a speedup attribute while holding down the mouse button.

example:

1) Player with current hp 160 and max hp 5000, and a potion that can heals 1-99999 hp (depending on the charges on it)

2) holding the mouse button down heals the player and at the same time use up the potion

3) before the player hp reach 5000 hp, the number will slow down.

the 1 * int((MaxHp - HP)/10) was an experiment for the speed up process.

LittleStain
1) sorry, a typo there. (earlier i had created an instant variable to test it out, works the same as a global tho...)
2) hp/10 is to reduce the amount gain immediately.

if
1 * ((max hp - hp ) / 10)

looks like this

1* ((5000 - 0) / 10)

without the /10 it will instantly heals the player.

at the same time, the healing factor will start high up and go down.


dropbox.com/s/ur14nlfbsx784fz/Hp%20Regen.capx

^^ capx is as above... just add the front part
Eastcr9w2014-01-08 13:30:45
B
8
S
2
Posts: 6
Reputation: 776

Post » Wed Jan 08, 2014 2:54 pm

is this what you are after ?

capx
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Wed Jan 08, 2014 11:51 pm

It is almost the same as what i have in mine

is there a way to make it fully uses up the heal? yours is not complete yet as it have a leftover of 5.
B
8
S
2
Posts: 6
Reputation: 776

Post » Thu Jan 09, 2014 8:49 am

I thought you wanted to just stop it going negative - anyway look at "lerp" as I think this is what you are after.

another go

basically this now takes 5% (look at global variable "gvPercentageToTakeFromReserve) of your remaining "Health left in bottle" (heal) and adds it to your hit points (Hp)

This does allow hit points to go over max hit points but then corrects in line 5 but you have still drank 5% of your remaining potion.

Another (better ?) way would be to say the bottle holds 10 gulps of potion and each gulp would heal half way between your health now and max health...

so that would become something like

if (gulps left in bottle) > 0
(my health)=(my Health)+lerp ((my health),(max Health),50)
reduce (gulps left in bottle) by 1
start some timer to allow time for potion to work

Good luck
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812

Post » Thu Jan 09, 2014 12:24 pm

Oh. This is wonderful.

Thank you very much RamPackWobble


ceil(lerp(0,heal,gvPercentageToTakeFromReserve))

so... it does this? (from the capx)

1) 0 to 10000(heal amount) takes 5% out.
2) Change the gvAmount then deduct and add it from others


nice! i gained a new achievement by learning lerp Eastcr9w2014-01-09 12:25:29
B
8
S
2
Posts: 6
Reputation: 776

Post » Thu Jan 09, 2014 12:57 pm

and "Thank you" for thanking me, that's all I ask for - and maybe a pint of Guinness if you ever see me out, possibly a packet of crisps and if you ever win the lottery....

As I understand it:

lerp (a,b,p)   takes the difference of a and b and then finds p of it
so lerp (a,b,0.5) would find halfway between a and b
lerp (5,9,0.5) would give 2

now in your case you only want a set percentage as we are always going from 0 so you would probably be better with setting gvHealingAmount to be heal*0.5 (if you wanted to take half for example) (we dont need the lerp)

but if you go with what I said above (one gulp heals half of your lost health) then lerp is ideal.

ceil (X) just rounds up the the next whole number.

yes - my version just take some of the health left in the bottle and add it to your players health.
August 2015 - I misplaced a lot of links - I will try to find backups and repost. If You find a post that interests please reply to post with @rampackwobble and I will get a nudge!

If you find my posts useful please consider donating something to a local charity or to the http://www.mndassociation.org/
B
64
S
33
G
47
Posts: 1,194
Reputation: 30,812


Return to How do I....?

Who is online

Users browsing this forum: Demkamen and 13 guests