Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: 00jon00 on Sun 29/02/2004 23:45:18

Title: Character Health
Post by: 00jon00 on Sun 29/02/2004 23:45:18
Does anybody know how to make it so my character can have health, and when he gets hit he loses some?  I want your 'health' to always be on the screen also, but I don't know how to do that ethier. Any ideas?
Title: Re:Character Health
Post by: Ishmael on Mon 01/03/2004 09:33:01
Basicly, just use a variable for the health... for example a globalint, say number 100 in this case. In the game_start global function, set the globalint to the health amount you want the character to have, and use the SetGlobalInt(INT, VALUE); to change the health. Like SetGlobalInt(100, -10); would decrease the player's health with 10.

To display it on the screen, create a GUI and a label on it. Set the label text to for example "Health: 100" and in the repeadetly_execute global function put:

StrFormat(hlthstr, "Heath:%d", GetGlobalInt(100));
SetLabelText(GUI, LABEL, hlthstr);

and in the beginning of the global script:

string hlthstr;

would make it display the health on the GUI you made. Just replace the GUI with the GUI name and LABEL with the label number.
Title: Re:Character Health
Post by: Fabiano on Mon 01/03/2004 16:03:30
using Setglobalint (100,-10); will turn the int(100) to -10 value, not 90.

I used that option:

if (GetGlobalInt(100)==10) SetGlobalInt(100,0);
if (GetGlobalInt(100)==20) SetGlobalInt(100,10);
if (GetGlobalInt(100)==30) SetGlobalInt(100,20);
if (GetGlobalInt(100)==40) SetGlobalInt(100,30);
if (GetGlobalInt(100)==50) SetGlobalInt(100,40);
if (GetGlobalInt(100)==60) SetGlobalInt(100,50);
if (GetGlobalInt(100)==70) SetGlobalInt(100,60);
if (GetGlobalInt(100)==80) SetGlobalInt(100,70);
if (GetGlobalInt(100)==90) SetGlobalInt(100,80);
if (GetGlobalInt(100)==100) SetGlobalInt(100,90);

but if the Health goes by -1 ~ -9 points dont work unless use one IF for each Health point.
Title: Re:Character Health
Post by: Ishmael on Mon 01/03/2004 16:05:22
Oops...

It goes this way:

SetGlobalInt(100, GetGlobalInt(100) - 10);
Title: Re:Character Health
Post by: Fabiano on Mon 01/03/2004 20:51:41
oh. Nice. better than 100 if lines  ;D

thankx Tk u helped me too
Title: Re:Character Health
Post by: 00jon00 on Mon 01/03/2004 22:55:59
Hey, Thanks a lot you guys, you all helped me out big time!! 8)
Title: Re:Character Health
Post by: 00jon00 on Mon 01/03/2004 23:17:53
Wait, It displays it and all, but for the actuall health it just displays a 0??(zero)
Title: Re:Character Health
Post by: Fabiano on Mon 01/03/2004 23:21:18
have u put in the beggining of the global script setglobalint(100,100); ?
Title: Re:Character Health
Post by: 00jon00 on Tue 02/03/2004 00:19:53
I tried that, but I just get an error saying:
---------------------------
Compile Error
---------------------------
There was an error compiling your script. The problem was in 'Main script':



Error (line 2): Parse error: unexpected 'SetGlobalInt'



Do you want to fix the script now? (Your game has not been saved).
---------------------------
Yes   No  
---------------------------

Title: Re:Character Health
Post by: 00jon00 on Tue 02/03/2004 00:26:27
whoops, lol! EXTREMELY STUPID error from me...I put it above The function game_start() command... ;D