Adventure Game Studio

AGS Support => Advanced Technical Forum => Topic started by: hedgefield on Mon 20/06/2011 11:57:13

Title: Retrieving the names of all characters in the room [SOLVED]
Post by: hedgefield on Mon 20/06/2011 11:57:13
Hey guys, I'm stumped on this piece of code here, maybe you can help me troubleshoot.

What I'm trying to do is retrieve a list of all the characters in the current room, so I can stick their names on GUI buttons.
So far I have this:

     int i = Button9.ID;
     int charindex = 0;  //sets starting point for character ID list
     while (i < (Button9.ID + 4)) {
       if (charindex < Game.CharacterCount) {  //if the current index does not exceed the total number of characters
         Character* cha;   //create a dummy character to store the real character
         cha.ID = charindex;   //dummy character becomes real character when given an ID
         if (cha.Room == player.Room) {  //if the character is in the same room as the player
           gDialog.Controls[i].AsButton.Text = cha.Name;   //put character name on button
           i++;
           charindex++;
         }
         else charindex++; //check the next character for the SAME button
       }
       else {
         gDialog.Controls[i].AsButton.Text = "";  //otherwise leave button blank
         i++;
       }
     }


Which should work I think aside from the fact that I cannot manipulate a character's ID.

I used a similar construction to do the same thing with inventory items, except inv items are listed in an index that I can query. I don't think there is something similar for characters, aside from Game.CharacterCount, is there?

And ideas on how I could get this to work?
Title: Re: Retrieving the names of all characters in the room
Post by: Khris on Mon 20/06/2011 12:50:05
Replace
          cha.ID = charindex;   //dummy character becomes real character when given an ID

with
          cha = character[charindex];   //dummy character becomes real character when given an ID
Title: Re: Retrieving the names of all characters in the room
Post by: hedgefield on Mon 20/06/2011 15:10:08
Somehow I knew I could count on you to have the answer to my problem, thanks Khris :)