Retrieving the names of all characters in the room [SOLVED]

Started by hedgefield, Mon 20/06/2011 11:57:13

Previous topic - Next topic

hedgefield

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:

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

Khris

Replace
Code: ags
          cha.ID = charindex;   //dummy character becomes real character when given an ID


with
Code: ags
          cha = character[charindex];   //dummy character becomes real character when given an ID


hedgefield

Somehow I knew I could count on you to have the answer to my problem, thanks Khris :)

SMF spam blocked by CleanTalk