GUI's Mana and Health

Started by PIT, Wed 06/09/2006 09:43:54

Previous topic - Next topic

PIT

I can't get health and mana working together they come up as the same.
I'm using the GiveScore(...); command for both, but they equal the same.

R4L

#1
Quote from: PIT on Wed 06/09/2006 09:43:54
I'm using the GiveScore(...); command for both

Thats why.

Try using Global Ints. You could do this:

SetGlobalInt(1,100);//health
SetGlobalInt(2,100);//mana

Then when you want to use mana for a spell you could call this:

if (GetGlobalInt(2) >= 50){
do stuff blah blah
}

You can change that little 50 in there too, so if it were 20 it would just say If GlobalInt(2) is greater than or equal to 20 then do this...

And for when you are damaged:
SetGlobalInt(1,GetGlobalInt(1)-25);

That says to take GlobalInt(1) and take 25 from it. Note that GetGlobalInt is in there because if you just set global int 1 to 25, that isn't very fair for the playerÃ,  :).

And say you die, in your Global Script, under repeatedly_execute:

if (GetGlobalInt(1) == 0){
TintScreen(100,0,0);
Display("Game Over, You Died.");
QuitGame(0);
}

Im sure you can identify those commands by nowÃ,  ;)

Get it? Get use to using ints, because they are quite flexible.

Also, look for a tutorial on the main site under resources, its by Ahmet CoolBlue-Gord and teaches the same things I just taught you, including weapons and spells.

monkey0506

You may also consider using structs:

Code: ags
struct RPGChar {
  Character* Char;
  int Health;
  int Mana;
  }

RPGChar rpgEgo;

// game_start
rpgEgo.Char = cEgo;
rpgEgo.Health = 100;
rpgEgo.Mana = 100;

// to use AGS's built-in Character functions, say, to make rpgEgo walk to point X, Y
rpgEgo.Char.Walk(X, Y);

// some function where rpgEgo takes damage, such as during a battle
rpgEgo.Health -= 20; // Ego loses 20 health

// some function where rpgEgo uses magic
rpgEgo.Mana -= 10; // Ego loses 10 mana

// etc., etc.

Khris

#3
PIT, I'm curious, how did you expect AGS to know the two apart if you just wrote GiveScore(x); for both?

EDIT: Rap4Life42o, QuitGame(0); will exit the game immediately.

monkey0506

But Display() is blocking, so it wouldn't exit until after the user clicked the mouse or pressed a key. Although the game just exiting every time you die could be annoying.

Khris

Is. :)
The other thing is that I don't think those random code snippets (R4L's) are very helpful, they'll only confuse newbies more.

R4L

Quote from: KhrisMUC on Wed 06/09/2006 18:48:35
EDIT: Rap4Life42o, QuitGame(0); will exit the game immediately.

I was just giving some example of what he could do when the player dies.

PIT

I already new how to make mana I just didnt know how to display it in the GUI. It always comes up with Mana: with no number.

-Sorry 4 not being specific.

monkey0506

You could put this code in your repeatedly_execute function:

Code: ags
lblMana.Text = String.Format("Mana: %d", MANA);


Where lblMana is the script o-name of your label, and MANA is whateve code you use to retrieve the mana value.

PIT

Ok that worked but it still comes up with Mana: ...

My first label is Mana:
the script name for it is lblMana

and my second is ...
the script name for this is MANA

how do I get ... to say the int Data of GlobalInt(2)?

monkey0506

Code: ags
lblMana.Text = String.Format("Mana: %d", GetGlobalInt(2));





...at least I think that's what you meant....

PIT

It works, but now the ... is dissapearing completly.

This is my code
lblMana.Text = String.Format("Mana: %d", GetGlobalInt(2));

and my ... script name is lblMana.
The game loads but the ... is disspearing.

monkey0506

How exactly do you want it to read?

Do you want it to say "Mana: ...#" where # is the amount of mana, or just "Mana: #" or.....what format do you want? The "..." should disappear...unless you don't want it to....? Do you want it to show "..." instead of 0?

PIT

I want it to say Mana: #
and i want the number to corrospond with GlobalInt(2)

Khris

MANA.Text = String.Format("%d", GetGlobalInt(2));

monkey0506

There's no need to use two labels. Just use one label and set it's text like I said before.

PIT

Quote from: monkey_05_06 on Wed 01/11/2006 15:16:46
There's no need to use two labels. Just use one label and set it's text like I said before.

Yes I understand that now.
The reason the text wasn't showing up was because my label was too short.
I understand how to do the labels.
Thank-You all for your help.

SMF spam blocked by CleanTalk