Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,631 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
player stats not working? #406391
08/19/12 06:46
08/19/12 06:46
Joined: Dec 2010
Posts: 100
D
Dega Offline OP
Member
Dega  Offline OP
Member
D

Joined: Dec 2010
Posts: 100
so i set up this code to make it where my stats don't exceed the max stats like HP and MP but it doesn't work right. Can someone tell me why?

Code:
var player_lvl = 1;
	var player_xp = 0;
	var player_max_hp = 1000;
	var player_max_mp = 1000;
	var player_hp = 1000;
	var player_mp = 1000;
	var player_dmg = 500;
	var player_def = 500;
while(1)
{
		if (player_xp >= 100 && player_lvl <= 10)
		{
			player_xp = 0;
			player_lvl += 1;
			player_dmg += integer(random(10)+50);
			player_def += integer(random(10)+50);
			player_max_hp += integer(random(100)+1000);
			player_max_mp += integer(random(100)+1000);
		}


		if (player_hp > player_max_hp)
		{
			player_hp = player_max_hp;
		}
		if (player_mp > player_max_mp)
		{
			player_mp = player_max_mp;
		}
		wait(1);
}




boolean my.awesomeness = so true;
Re: player stats not working? [Re: Dega] #406395
08/19/12 09:00
08/19/12 09:00
Joined: Apr 2008
Posts: 650
Sajeth Offline
User
Sajeth  Offline
User

Joined: Apr 2008
Posts: 650
Since your hp equals your max hp and you are incrementing by an value greater than what your max hp is... I'm not really sure what you're trying to achieve here.


Teleschrott-Fan.
Re: player stats not working? [Re: Sajeth] #406398
08/19/12 10:08
08/19/12 10:08
Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Espér Offline
Expert
Espér  Offline
Expert

Joined: Mar 2008
Posts: 2,247
Baden Württemberg, Germany
Code:
if (player_hp > player_max_hp)
		{
			player_hp = player_max_hp;
		}
		if (player_mp > player_max_mp)
		{
			player_mp = player_max_mp;
		}



can be replaced ith:
Code:
player_hp = clamp(player_hp, -1, player_max_hp)
player_mp = clamp(player_mp, -1, player_max_mp)



this codes holds the hp/mp between -1 and the maximum values.. -1 ables you to handle the value 0 or below, too.

else.. the code looks okay to me.. when is the problem appearing?


Selling my Acknex Engine Editions (A7 Com & A8 Pro):
>> click here if you are interested <<
Re: player stats not working? [Re: Espér] #406421
08/19/12 20:54
08/19/12 20:54
Joined: Dec 2010
Posts: 100
D
Dega Offline OP
Member
Dega  Offline OP
Member
D

Joined: Dec 2010
Posts: 100
the clamp part worked. Thanks again esper! the old code would make my characters hp go down into the negatives! I dunno why though.


boolean my.awesomeness = so true;

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1