From 283fbc85a91f75c669e03550b602b5e6f0f27308 Mon Sep 17 00:00:00 2001 From: MysterD Date: Fri, 4 Mar 2022 23:20:53 -0800 Subject: [PATCH] Add notes on player indices to Lua docs --- docs/lua/lua.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/docs/lua/lua.md b/docs/lua/lua.md index e940d70c..e7d1a467 100644 --- a/docs/lua/lua.md +++ b/docs/lua/lua.md @@ -26,6 +26,20 @@ Lua scripts you make can be placed either the `mods` folder in the base director
+## Important notes on player indices + +Something important to realize is that the `localIndex` for each player is different (unfortunately). + +So the order of `gMarioStates[]`, `gNetworkPlayers[]`, and `gPlayerSyncTable[]` is different for each player. + +Luckily `gPlayerSyncTable[]` will automatically translate the player indices, so setting `gPlayerSyncTable[0].example = 1` will set it for the correct player for everyone. + +The `globalIndex` of each player is consistent among everyone connected. So if you absolutely need to sort things in order you will have to grab it from `gNetworkPlayers[].globalIndex`. + +All of this is a holdover from when there were only two players. It was a reasonable idea back then. + +
+ ## Example Lua mods - [Extended Moveset](../../mods/extended-moveset.lua) - [Character Movesets](../../mods/character-movesets.lua)