Character-specific variables help

Started by Flim, Mon 09/02/2004 01:55:41

Previous topic - Next topic

Flim

Hi, I'm trying to make a game with sort of RPG elements where you can choose between a number of characters, and I'd like to know how one would go about creating new character-specific variables. Things like character[ego].room or character[ego].activeinv, only something like character[ego].strength and character[ego].intelligence, stuff like that.

Thanks a lot!

Bernie

I'm not sure if it's possible to add functions like those, but you could simply use global integers instead. You can add to em, subtract from em, multiply em and divide em and whatnot, those should do the trick for any kind of RPG stats.

Is this a game where you pick a character at the start and play the game with it or are more characters available to play with during the game?

Gilbert

Just make arrays to hold them.
For example, there're a total of 20 characters (and you're sure their character ids are just 0 thru 19).

Just define variables like:

int health[20], intelligence[20];
export health, intelligence;

on top of the global script.


Then add the line:

import health, intelligence;

to your script header.

You can then refer to them like health[EGO], etc everywhere in your scripts.

a-v-o

you can use custom properties.

See characters - properties...

and SetCharacterProperty, GetCharacterProperty

Rui 'Trovatore' Pires

Quote from: a-v-o on Mon 09/02/2004 19:22:12
you can use custom properties.

See characters - properties...

and SetCharacterProperty, GetCharacterProperty


Er, no. You can GET the properties, yes, but you can't change them at run-time, we're still bugging CJ to allow it  ::). SetCharacterProperty refers to the "No diagonal loops" and "Character Turn before walking" thingamagigs.
Reach for the moon. Even if you miss, you'll land among the stars.

Kneel. Now.

Never throw chicken at a Leprechaun.

a-v-o

huh... you're right. I only read the Get... in the helpfile and thought Set... would be the corresponding function, but it's something different.

RickJ

#6
You can do something with global structures (i.e. strct) as follows:

Global Script
// Create a custom data type  consisting of AGS built-in data types
struct  CHAR_DEF
{
int  strength;
int  intelligence;
int  whatever;
int  weapon[100];
}

// Declare a variable array named "Character" of type CHAR_DEF defined above.
// Note that variable names are case sensitive so "Character" is a different variable
// than the built-in AGS variable "character".   An array is used so that there will be
// one  array element for each character.  Each element will contain strength,
// intelligence, whatever, and weapons.  The weapons element is also an array.

// Declare variable
CHAR_DEF Character[150];

// Export variable so it can be used globally
export Character;

// I am not exactly sure about the  syntax and I am at work right now, so I can't test
// it out to be sure.  Structs are not an official feature so they may not be in the
// manual.  Perhaps some others who are familiar with them can correct my syntax.


Script Header
// Import variable so it can be used globally
import Character;


Room Script
// Any interaction function
function room_b() {

int room;
int intelligence = 100;
int strength = 50;

// Get the current room number
room = character[EGO].room;

// Initialize extra character attributes
Character[EGO].intelligence = intelligence;
Character[EGO].strength = strength;
Character[EGO].whatever = 0;
Character[EGO].weapon[20] = 100;
Character[EGO].weapon[2] = 100;
}

I think this is what you are looking for.  The custom properties, I think, are more static and are more or less meant to be changed at design time via AGSEDIT.

Hope this is helpful

Cheers
Rick

SMF spam blocked by CleanTalk