Hi Guys,
What's the best way to define some statistics about a character?
CharacterA (Stat1,Stat2,Stat3,Stat4);
I want to be able to set the statistics / values independantly and read them independantly.
CharacterA (Stat1 == 1);
If CharacterA (Stat1 == 1) do this
Also, if each character can have their own inventory, how can I check to see if they have a specific item?
Many Thanks
Pete
Hi PSP!
Have you checked out the section about properties in the manual? I think that may give you the answer you may need.
Sorry if this wasn't helpful, and if it was, glad to help.
JD
QuoteWhat's the best way to define some statistics about a character?
Do you just want to have stats about the player character, or for lots of different characters? If it's just the one, you can have variables, eg:
int stat1, stat2, stat3;
which contain the various information. If it's for all character, you can use arrays:
int stat1[150], stat2[150], stat3[150];
then access them using the character ID, for example:
stat1[EGO] = 54;
QuoteAlso, if each character can have their own inventory, how can I check to see if they have a specific item?
if (character[CHARID].inv[INV_NUMBER]) {
// they have the item
}
Thanks JD,
Properties? Hmm, they look new! I'll have to sit down and have a play with them.
Chris,
It would be for lots of different characters. to store whether they had gone to jail, or how much money that had collected - would your suggestion still work if I defined an int in the global script for each character?
CharacterA jail[1], headcount[2], money[200];
CharacterB jail[1], headcount[2], money[200];
Which I can then affect directly
jail[CHARA] = 0;
money[CHARB] = 200;
Thanks for the inventory tip, it's been a while since I sat down for some hardcore AGS, and I'm a little rusty.
Pete
I think you're misunderstanding how arrays work.
You need to define:
int jail[150], headcount[150], money[150];
that assumes that you have a maximum of 150 characters - if you have more, you'd need to increase those numbers.
Then, yes you can do:
jail[CHARA] = 0;
money[CHARB] = 200;
You're correct Chris, I'd gotten the complete wrong end of the stick (or array) ;D
So I define my ints by first setting a size for the array, in your example 150 for each of the three values.
Then I place a value in the array by calling the int, followed by a unique tag for that item, followed by the value. If I tried to put more than 150 values in your array I would loose the first value?
Is there a simple way to view the values within the array?
Thanks for your help, this is a big step up from NewRoomEx and globalints, but I'm determined to take it - can anyone reccommed any examples within AGS?
Pete
You mean ALL the values at the same time? You'd want to construct a while loop.
Otherwise, Display("%d", jail[EGO])
Quote from: pleasuresuitpete on Mon 08/12/2003 22:20:16
Then I place a value in the array by calling the int, followed by a unique tag for that item, followed by the value. If I tried to put more than 150 values in your array I would loose the first value?
Declaring this:
int jail[150];
creates an array with 150 slots for you to use.
The use of character names confuses the issue a bit because they actually map to numbers - so ignore that for now.
So if you do:
jail[30] = 1;
you set the 30th slot in the array to 1. You can use each slot just like any other variable, for example
if (jail[56] == 1) {
}
or
Display("%d", jail[60]);
If you write to the same slot twice, you overwrite the previous value, just like any other variable. Do not try and access a slot number above the size of the array, or AGS will crash. ie do NOT do this:
jail[466] = 2;
it will produce undesirable results.
Brilliant Chris, thanks for your help.
I do believe I might have finally got this (huge sigh of relief from the audience).
Back to my coding hole I go!
Pete