Difference between revisions of "AI War 2:Custom Text Messages To The Player"

From Arcen Wiki
Jump to navigation Jump to search
Line 4: Line 4:
 
What is presented below is an older form of "journal entry," which is just embedded in the chat log.  It can be useful to do that sort of thing at various points as well, but those are... less robust.  The journal entries that we're referring to at the above link is instead like uncovering little wiki entries, almost, that show up in a dedicated tab in your sidebar as you play.
 
What is presented below is an older form of "journal entry," which is just embedded in the chat log.  It can be useful to do that sort of thing at various points as well, but those are... less robust.  The journal entries that we're referring to at the above link is instead like uncovering little wiki entries, almost, that show up in a dedicated tab in your sidebar as you play.
  
= Original Q&A =  
+
= Revised Q&A =  
  
 
'''Q:''' Do you have sample code for how to emit different journal entries? For example, I'd like a permanent journal entry at game start when you have allied marauders that basically explain how marauders work, and that they can build Raiders if they have their own planets.
 
'''Q:''' Do you have sample code for how to emit different journal entries? For example, I'd like a permanent journal entry at game start when you have allied marauders that basically explain how marauders work, and that they can build Raiders if they have their own planets.
  
'''A:''' Sure -- it's super easy, thankfully, and just piggybacking on our existing code for sending players messages.
+
'''A:''' This has changed a LOT! 
  
1. First off, to have something show up in the sidebar log for a second and then NOT go to the journal (aka behavior up until now), you need to do this sort of thing:
+
=== Where Do Do That Sort Of Permanent Logging ===
  
            World_AIW2.Instance.QueueLogMessageCommand( "Not enough energy to place " + typeToPlace.DisplayName, JournalEntryImportance.NeverLogCentrally, "CannotDoThatThing", context );
+
Now you will find the new instructions for that in the [[AI_War_2:_Journal_Entries#Q.26A_On_How_To_Log_Journal_Entries_From_Custom_Code|Q&A On How To Log Journal Entries From Custom Code]].
  
There are several overloads, but it's the new NeverLogCentrally that matters.
+
=== Why We'd Use This Instead ===
  
2. Taking a step up from that, let's log it to the journal but consider it no more important than the average chat message.  So if the players are chatting heavily in multiplayer via text chat for some reason, this will get knocked off the list fast.  These are any of the overloads of the method, but along these lines:
+
So we've established at this point that nothing we do here is actually permanent, correct?
  
            World_AIW2.Instance.QueueLogMessageCommand( "Human Resistance Fighters arriving to reinforce " + targetPlanet.Name, JournalEntryImportance.Normal, "HumanResistanceFightersWarpInNeutralPlanet" , Context );
+
Okay. So, our purpose here is just to write to the chat log. This means a little popup on the right side of the screen for 10 seconds, and then it's visible in the chat window until 50 more messages are loggedOnly the last 50 chat log messages are kept, whereas all journal entries are kept forever.
  
They have an importance of normal.
+
The goal of using something like this is probably to tell people about something that is happening right now ("hey, marauders are back for the 80th time, just thought you should know") in a conversational way that really makes them notice it, but without logging it forever (seriously, a journal full of 80 marauder attacks would be so overstuffed as to be incomprehensible.
  
3. Next step up is stuff to "keep longer."  When it culls the list of journal entries down to 50, it first clears all the normal ones, then only starts clearing the oldest of these keeplonger ones if there are still more than 50 messagesSo these should be used for mid-tier importance stuffSomething that's important maybe for a few hours, I guess, but not an absolute turning point in the game.
+
One thing you should NOT do is use this AND a journal entry call for permanent logging. Why?  Journal entries have chat_text built right in as a field on them, and they will already send a message to the chat log when they arrive, if the journal entry author feels that is warrantedTrust the journal entry authorIf you do both, probably players will get double messages.
  
Actually, your thing that explains how marauders work I feel like falls under this category -- it probably won't disappear in a regular game, at least not for a lot of hours (think of the flow of messages here, you'd have to have more than 50 keeplonger or neverdiscard messages all in there clogging stuff up for this to ever go away.
+
So here are some use cases for this sort of thing:
  
You could even make the argument that you might just want to use Normal importance, so that it disappears if 50 more messages or chats get sent. How long is this really relevant?  Etc.  But I think that for the intro message at least, it being keeplonger might make sense.  Most other events that aren't absolutely pivotal to the game (even things like a spire relic being captured) should probably just be normal events.  Unless they're the sort of things a player might look back on and go "where did I hit X milestones in my quest?"
+
1. First off, to have something show up in the sidebar log for a second and then NOT go to the chat log -- and while we're at it, only go to the local player:
  
             World_AIW2.Instance.QueueLogMessageCommand("A Scourge Nemesis has spawned in the galaxy!", JournalEntryImportance.KeepLonger, null);
+
             World_AIW2.Instance.QueueChatMessageOrCommand( "Not enough energy to place " + typeToPlace.DisplayName, ChatType.ShowLocallyOnly, "CannotDoThatThing", context );
  
4. The strongest type is never discard, which stays absolutely forever.  You won the game, the game majorly majorly changed in a way that happens almost never, etc.  Ideally there would not be more than maybe 10 of these in a game so there's still 40 journal spots for the other things.  Also ideally, the total of keeplonger and neverdiscard would never be more than 25-30 in a game, or else I'll need to let the journal be longer than it is now. We can figure that out as we go.
+
There are several overloads, but it's the new ChatType.ShowLocallyOnly that matters.
  
But an example:
+
2. Taking a step up from that, let's tell everyone and dump that in the general chat log:
  
             World_AIW2.Instance.QueueLogMessageCommand( "The AI Civil War has begun", JournalEntryImportance.NeverDiscard, "", Context );
+
             World_AIW2.Instance.QueueChatMessageOrCommand( "Human Resistance Fighters arriving to reinforce " + targetPlanet.Name, ChatType.LogToCentralChat, "HumanResistanceFightersWarpInNeutralPlanet", Context );

Revision as of 14:52, 7 May 2020

Hey!

Do you really mean " Journal Entries", in the sense of those things that are defined in xml and new in version 2.040 of the game and further? If so, click that link. Those are what you should be using for long-term, detailed journal entries. And as a bonus, they don't require any custom code from you.

What is presented below is an older form of "journal entry," which is just embedded in the chat log. It can be useful to do that sort of thing at various points as well, but those are... less robust. The journal entries that we're referring to at the above link is instead like uncovering little wiki entries, almost, that show up in a dedicated tab in your sidebar as you play.

Revised Q&A

Q: Do you have sample code for how to emit different journal entries? For example, I'd like a permanent journal entry at game start when you have allied marauders that basically explain how marauders work, and that they can build Raiders if they have their own planets.

A: This has changed a LOT!

Where Do Do That Sort Of Permanent Logging

Now you will find the new instructions for that in the Q&A On How To Log Journal Entries From Custom Code.

Why We'd Use This Instead

So we've established at this point that nothing we do here is actually permanent, correct?

Okay. So, our purpose here is just to write to the chat log. This means a little popup on the right side of the screen for 10 seconds, and then it's visible in the chat window until 50 more messages are logged. Only the last 50 chat log messages are kept, whereas all journal entries are kept forever.

The goal of using something like this is probably to tell people about something that is happening right now ("hey, marauders are back for the 80th time, just thought you should know") in a conversational way that really makes them notice it, but without logging it forever (seriously, a journal full of 80 marauder attacks would be so overstuffed as to be incomprehensible.

One thing you should NOT do is use this AND a journal entry call for permanent logging. Why? Journal entries have chat_text built right in as a field on them, and they will already send a message to the chat log when they arrive, if the journal entry author feels that is warranted. Trust the journal entry author. If you do both, probably players will get double messages.

So here are some use cases for this sort of thing:

1. First off, to have something show up in the sidebar log for a second and then NOT go to the chat log -- and while we're at it, only go to the local player:

            World_AIW2.Instance.QueueChatMessageOrCommand( "Not enough energy to place " + typeToPlace.DisplayName, ChatType.ShowLocallyOnly, "CannotDoThatThing", context );

There are several overloads, but it's the new ChatType.ShowLocallyOnly that matters.

2. Taking a step up from that, let's tell everyone and dump that in the general chat log:

            World_AIW2.Instance.QueueChatMessageOrCommand( "Human Resistance Fighters arriving to reinforce " + targetPlanet.Name, ChatType.LogToCentralChat, "HumanResistanceFightersWarpInNeutralPlanet", Context );