Death (FIXED)

Started by ncw14, Mon 24/12/2007 02:53:28

Previous topic - Next topic

ncw14

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

Baron

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

ncw14

score is an undefined symbol

Gilbert

Look up game.score from the manual.

Baron

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)

ncw14

#5
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

Khris

It's "int health=100;"

Reducing it by 10: "health=health-10;" or simply "health-=10;"

ncw14

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

VK Dan

Yep. You can say that easily

Code: ags

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


To show the health on your GUI can can put
Code: ags

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)

ncw14

#9
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

R4L

Couldn't you use a struct? Like:

Code: ags

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


VK Dan

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
Code: ags

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:
Code: ags

if (health <=0) 
{
    //The code you want to run when he dies.
}

ncw14

I'm trying that but an easier thing would be

if (game.score < 1)

but it says error expected '('
where do i put it

ncw14

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

monkey0506

Please read the manual's Scripting tutorial. It will explain a lot about scripting with AGS.

SMF spam blocked by CleanTalk