Charactername in a variable [solved]

Started by arj0n, Thu 16/05/2013 14:05:10

Previous topic - Next topic

arj0n

I'd like to know how I can use a charactername (cEgo for example) in a variable so I can use the variable and only have to declare the specific name once.
Example:
Code: AGS

// room script file
String Player1;

function room_AfterFadeIn()
{
Player1 = cEgo;
}

function room_RepExec()
{
if (player==Player1)
  {
if (((NpcIsFollowing == false) && ((cEgo.x <= (cMerchant.x))......
//more code//
}


With for example 'String' I get a 'Type mismatch: cannot convert 'Character*' to 'String*'' at the 'Player1 = cEgo;' line.

Khris

All you need is a pointer:
Code: ags
Character* Player1;

arj0n


Ryan Timothy B

#3
On a side-note there is also: Character.ID
Code: ags
int ID = cEgo.ID;

if (ID == player.ID)
//OR
if (character[ID] == cEgo) 


But yes, I prefer to use a character pointer in an instance like this.

Phemar

For a string there's also Character.Name. But yea, it's better to use a pointer.

SMF spam blocked by CleanTalk