Adventure Game Studio

AGS Support => Beginners' Technical Questions => Topic started by: ncw14 on Mon 24/12/2007 02:53:28

Title: Death (FIXED)
Post by: ncw14 on Mon 24/12/2007 02:53:28
Im Making an Rpg

My Characters health is the score but no matter the code i use it always ends up not letting him die and his health goes to negatives, so under repeatedly execute what code should i use for

if score <=0 then you change room to room 24
Title: Re: Death
Post by: Baron on Mon 24/12/2007 03:06:50
Something like this should do it:

if (score <= 0) cPlayer.ChangeRoom (24);

Of course you'll probably want to add an animation and other effects, so you'd need braces around the code if it's going to be more than the one line I have above.

Baron
Title: Re: Death
Post by: ncw14 on Mon 24/12/2007 03:16:43
score is an undefined symbol
Title: Re: Death
Post by: Gilbert on Mon 24/12/2007 03:20:16
Look up game.score from the manual.
Title: Re: Death
Post by: Baron on Mon 24/12/2007 04:37:55
Ah....  It's kind of confusing to use score to represent health anyway.  Why not create a variable named "health"?

int health =100;   //(at the beginning of your script)
Title: Re: Death
Post by: ncw14 on Mon 24/12/2007 15:33:45
I'm kind of confused on

int

so if i did

int health ==100

would i have to script something else for it to be recognized
and how would i lower the health like
(health -10)?


however i would like to not have to edit my whole script by that because im far in the game so if i could stick to the score one that would help a whole lot
Title: Re: Death
Post by: Khris on Mon 24/12/2007 16:45:50
It's "int health=100;"

Reducing it by 10: "health=health-10;" or simply "health-=10;"
Title: Re: Death
Post by: ncw14 on Mon 24/12/2007 18:39:40
well then all my scripts have to be changed is there any possible way to say

if score <= 0


also id have no way of knowing how to show health on GUI that way
Title: Re: Death
Post by: VK Dan on Mon 24/12/2007 18:52:48
Yep. You can say that easily


if (health <= 0)
{
   //Do whatever happens when your player dies.
}


To show the health on your GUI can can put

LabelWithHealth.Text = String.Format("%d", health);

inside repeatedly_execute, and it will update your health label on the GUI. (Note: You have to change LabelWithHealth to the name of the label that shows your health)
Title: Re: Death
Post by: ncw14 on Mon 24/12/2007 19:08:29
so all i would have to do it that then for every battle instead of

GiveScore (-25)

make it

health=health-25
?

it tells me undefined token health

how do i define it



now it says cannot convert String*Int


this is what i have under game_start for int
int health = 100'

under repeatedly_execute i have

if (health <= 0)}


how do i define it
Title: Re: Death
Post by: R4L on Mon 24/12/2007 19:30:59
Couldn't you use a struct? Like:


struct Health {
  int max;
  int min;
  String name; //in case you want to show player name
};

Title: Re: Death
Post by: VK Dan on Mon 24/12/2007 19:39:01
Quote from: ncw14 on Mon 24/12/2007 19:08:29
so all i would have to do it that then for every battle instead of

GiveScore (-25)

make it

health=health-25
?
Yes. A shorter way to do it would be

health -= 25;


Quote
it tells me undefined token health

how do i define it



now it says cannot convert String*Int


this is what i have under game_start for int
int health = 100'
The problem is that you declared health inside game_start. This means that you can only use this variable inside of game_start. You need to declare it at the very top of your global script.

Quote
under repeatedly_execute i have

if (health <= 0)}


how do i define it
It needs to have an opening brace as well. Something like this:

if (health <=0)
{
    //The code you want to run when he dies.
}
Title: Re: Death
Post by: ncw14 on Mon 24/12/2007 19:53:28
I'm trying that but an easier thing would be

if (game.score < 1)

but it says error expected '('
where do i put it
Title: Re: Death (FIXED)
Post by: ncw14 on Mon 24/12/2007 20:38:31
Quote from: ncw14 on Mon 24/12/2007 02:53:28
Im Making an Rpg

My Characters health is the score but no matter the code i use it always ends up not letting him die and his health goes to negatives, so under repeatedly execute what code should i use for

if score <=0 then you change room to room 24


i fixed it sorry people thaank you
Title: Re: Death (FIXED)
Post by: monkey0506 on Mon 24/12/2007 22:24:30
Please read the manual's Scripting tutorial (http://americangirlscouts.org/agswiki/Scripting_tutorial_part_1). It will explain a lot about scripting with AGS.