Chatbox-like Dialogue

Started by bulka_tarta, Sun 26/02/2017 22:51:31

Previous topic - Next topic

bulka_tarta

Ha, that was simple enough! It all works like a dream now :D

Thanks for the tips!

Oh, and sorry for being such a pain in the lower back :P

bulka_tarta

#21
Hey,

Sorry, it's me again. I'm struggling with something different this time around regarding the chat.

I'm trying to get the chat to disappear after talking to someone and then to reappear when you talk to a different person. The chat should stay visible for the period you are talking to the same character, so for example; you get two messages, they stay on the screen, you solve a puzzle, new messages ADD to the same chat. When you have completely finished talking to this character, the chat clears. When you get a new message, from someone else, all the previous messages disappear and new ones are in place. The idea is that the stuff you do for different characters are not directly related to each other, but it all should be using the same chat window.

Simply creating a new chat each time around seems to do the trick (it clears the previous chat, and lets me to add new messages to the new one) but it seems like I'm just throwing more stuff at the game. I would imagine that deleting a chat and creating a new one (named the same) would just replace the old one, but eventually I reach the limit of the chats available and the game crashes:
"Array index out of bounds", line 155
Code: ags
chatWindow[chatWindows].button = button;

I could increase the number of chats, but it doesn't feel like an elegant way of doing this stuff.

I tried doing a "Chat.CleanUp()" or "Chat.Clear()" after all messages are displayed but I get an error: "DynamicSprite: Cannot get graphic, sprite has been deleted" on line 315.
Code: ags
chatWindow[c].button.NormalGraphic = chatWindow[c].currentView.Graphic;

and on line 358
Code: ags
if (b != null && b.OwningGUI.Visible && b.Visible) UpdateChatWindow(i);


I was trying to figure out a way to get around it, but I'm not sure how you could approach this. Would creating a new chat each round be actually fine (but increase the number of chats limit)? Or should I try something else?

Khris

Chat.CleanUp() is deleting all the DynamicSprites; don't call that unless it's followed by QuitGame(0); ;)

Chat.Clear(0); should do the trick. In theory, multiple chats are only needed when you want them to appear on screen at the same time. In reality, if you want chats with multiple people, you'll want to use more than one (otherwise you'd have to remember and restore all the messages so far each time you displayed the chat for an NPC) but I figured 10 is enough.

I actually forgot the MAX_CHATS check in Chat.Create(...) though :-\

bulka_tarta

Hmm... Chat.Clear doesn't seem to be working for me. I just double checked. It keeps crashing the game, with the error like in my previous post.

What I'm trying to achieve is something similar to Papers, Please. Basically you chat with a different person every time, and when you're done, it's gone and no longer relevant, so there's no need to store what the previous character has said.

I currently got this to work by creating a new empty chat every time you finish talking to a person. Creating a new chat clears the previous messages, and since there are no messages to display it keeps the chat empty until I do: Chat.Prepare and Chat.Advance.

The problem I have is that after 10 chats have been created, the game crashes. Of course, I can simply increase MAX_CHATS, but I was wondering if there would be a better way to do this.

Khris

You're right, I apparently never tested the .Clear() command.  :-[

Change the function to this (lines 8 - 15 of this snippet changed):
Code: ags
static void Chat::Clear(int c) {
  for (int i = 0; i < messages; i++) {
    if (message[i].chatID == c) {
      if (message[i].ms != null)  message[i].ms.Delete();
      message[i].chatID = -1;
    }
  }
  if (chatWindow[c].allSprites != null) {
    chatWindow[c].allSprites.Delete();
    chatWindow[c].allSprites = null;
  }
  if (chatWindow[c].currentView != null) {
    chatWindow[c].currentView.Delete();
    chatWindow[c].currentView = null;
  }
  chatWindow[c].messages = 0;
  chatWindow[c].messagesPosted = 0;
}


That way the UpdateView() function will properly recreate the sprite.

bulka_tarta

Works perfectly.

I really appreciate it Khris.
I guess I owe you a pint (or two)  ;-D

SMF spam blocked by CleanTalk