Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Subscribe to game Messages: Difference between revisions

From Kerbal Space Program 2 Modding Wiki
Spacewarp>Falki
m Change link from github to spacedock
m 8 revisions imported
 
(4 intermediate revisions by 3 users not shown)
Line 1: Line 1:
Game triggers a bunch of Messages (events) you can subscribe to in your code in order to react to those messages.
[[Category:Messages]]
The game triggers a bunch of Messages (events) you can subscribe to in your code in order to react to those messages.


For instance ''<code>VesselDeltaVCalculationMessage</code>'' for whenever the game is doing updates to any vessel deltav, or ''<code>UIButtonClickedMessage</code>'' for when the player clicks on any UI element.
For instance ''<code>VesselDeltaVCalculationMessage</code>'' for whenever the game is doing updates to any vessel deltav, or ''<code>GameStateChangedMessage</code>'' for when the player enters a different screen (e.g. Flight state -> KSC state).


You could always do any check inside an ''Update()'' method of your plugin class, but using Messages is more efficient when you need to do checks on events that are not triggered very often.
You could always do any check inside an ''Update()'' method of your plugin class, but using Messages is more efficient when you need to do checks on events that are not triggered very often.
Line 9: Line 10:
'''To see what Messages are being triggered on certain events you an use the <code>ShowKSP2Events</code> mod:'''
'''To see what Messages are being triggered on certain events you an use the <code>ShowKSP2Events</code> mod:'''


https://spacedock.info/mod/3375/ShowKSP2Events.
https://spacedock.info/mod/3375/ShowKSP2Events, or download it with CKAN
 
 




Line 17: Line 16:


[[File:ShowKSP2Events 1.2.0.png|left|thumb|1000x1000px]]
[[File:ShowKSP2Events 1.2.0.png|left|thumb|1000x1000px]]
[[Category:Tools]]

Latest revision as of 17:45, 9 October 2024

The game triggers a bunch of Messages (events) you can subscribe to in your code in order to react to those messages.

For instance VesselDeltaVCalculationMessage for whenever the game is doing updates to any vessel deltav, or GameStateChangedMessage for when the player enters a different screen (e.g. Flight state -> KSC state).

You could always do any check inside an Update() method of your plugin class, but using Messages is more efficient when you need to do checks on events that are not triggered very often.


To see what Messages are being triggered on certain events you an use the ShowKSP2Events mod:

https://spacedock.info/mod/3375/ShowKSP2Events, or download it with CKAN


This mod displays Messages as they are being triggered, colors them to make it easier to see when the event was triggered and it keeps a count of how many times an event has been triggered so far.

File:ShowKSP2Events 1.2.0.png