How to display a global int to the status bar (GUI)

Started by Nishuthan, Sat 14/10/2017 19:39:25

Previous topic - Next topic

Nishuthan

Hi I'm new to ags and I have a few game parameter like money health and knowledge I want to display then in the status bar.is there any way to do that and I also mant to check every time that health !=0 if health = 0   ii want to reset the game.


Thank you

Slasher

#1
Make some variable ints for health etc etc and labels to display their values...

eg

Open Global Variables Panel in the editor, right click to add new variable.
Name: Health 
Type: Int
Value: 100 // what ever your maximum health is.

Make a label on the gui and Name it say LHealth_Status

In Global.asc in repeatedly_execute_always()

add the label name like this:

Code: ags

   LHealth_Status.Text=String.Format("%d",Health);


This has a default Value of 100.

If you want to minus 5 from Health simply use this in script where you want it to apply...

Code: ags

// After doing this
    Health -=5;
// This will make your health read 95 (100 -5)


of course it depends how you want it displayed..

Just check the status of Health and run events accordingly..

Code: ags

if(Health <=0) // Health is at or lower than 0
 RestartGame();


You could even use a health bar that reduces as it lowers...or rises with more health.

This is a starting place...



SMF spam blocked by CleanTalk