Event Queue
Event Queue
Event Structure:
table Event
{
EventType m_type = EventType::Invalid;
ComplexColor m_oldPlayerNameColor;
string m_oldPlayerName;
string m_oldPlayerName2;
ComplexColor m_playerNameColor;
string m_playerName;
string m_playerName2;
int m_oldPlayerID;
int m_playerID;
string m_cmd;
string m_text;
int m_unitID;
int m_itemPickupUnitID;
string m_location;
string m_itemUd;
string m_itemTag;
string m_customSpellEventTag;
string m_ud;
string m_unitTag;
DeathCause m_deathCause;
int m_killerPlayerID;
Vec2<float> m_pos;
float m_radius;
int m_soundID;
bool m_bVal;
ExplosionEventType m_explosionEventType;
}
- Look at the comments in the definition of EventType to see which fields each
EventTypepopulates. m_playerName2has color information already encoded into the string, which is what you usually want to use.- equivalent to:
Unicode.Special_PushColor + gx_str_encode_complex_color(m_playerNameColor) + m_playerName + Unicode.Special_PopColor
- equivalent to:
- TODO: Better explain which fields are populated depending on
m_type- Until then, you can use the
gx_to_debug_stringfunction to output the fields/values - example:
print(gx_to_debug_string(ev, true))
- Until then, you can use the
Example of reading events from queue
function gx_sim_update()
{
while (!gx_is_event_queue_empty())
{
local ev = gx_pop_event_from_queue()
if (ev.m_type == EventType.PlayerLeftGame)
{
print("Player " + ev.m_playerID + " has left the game!")
}
else if (ev.m_type == EventType.PlayerNameChanged)
{
print(ev.m_oldPlayerName + " changed name to " + ev.m_playerName)
}
}
# do rest of game logic
}
Functions that operate on event queue:
Note:
- Any unpopped events are automatically popped off of queue after each gx_sim_update call.