The parser for the mission header section of the server config seems rather limited:
- Cannot parse numbers without periods for float attributes
- Cannot parse true and false for boolean attributes
The parser for the mission header section of the server config seems rather limited:
I created and published a test mod with the ID 5EAC510A8E6EC623, which contains the following code and in essence defines a float and boolean attribute for the mission header and prints their values in the chat for all clients:
//------------------------------------------------------------------------------------------------ modded class SCR_MissionHeader : MissionHeader { [Attribute(defvalue: "11.0", desc: "My mission header float variable")] float m_fMHT_myFloatVariable; [Attribute(defvalue: "false", desc: "My mission header boolean variable")] bool m_bMHT_myBooleanVariable; } //------------------------------------------------------------------------------------------------ modded class SCR_BaseGameMode : BaseGameMode { //------------------------------------------------------------------------------------------------ //! Schedule printing of my header variable override protected void OnGameStart() { super.OnGameStart(); if (!Replication.IsServer()) return; GetGame().GetCallqueue().CallLater(MHT_PrintMyVariable, 1000, true); } //------------------------------------------------------------------------------------------------ //! Broadcast and print my variable to all clients protected void MHT_PrintMyVariable() { SCR_MissionHeader header = SCR_MissionHeader.Cast(GetGame().GetMissionHeader()); if (!header) return; Rpc(MHT_PrintInChatBroadcast, string.Format("m_fMHT_myFloatVariable = %1\nm_bMHT_myBooleanVariable = %2", header.m_fMHT_myFloatVariable, header.m_bMHT_myBooleanVariable)); } //------------------------------------------------------------------------------------------------ //! Print chat message for all clients [RplRpc(RplChannel.Unreliable, RplRcver.Broadcast)] protected void MHT_PrintInChatBroadcast(string message) { PlayerController ctrl = GetGame().GetPlayerController(); if (!ctrl) return; SCR_ChatComponent.Cast(ctrl.FindComponent(SCR_ChatComponent)).ShowMessage(message); } }
{ "bindAddress": "", "bindPort": 2401, "publicAddress": "", "publicPort": 2401, "game": { "name": "Kex's Mission Header Test", "passwordAdmin": "pw", "scenarioId": "{83D06A42096F671C}Missions/MpTest/10_MpTest.conf", "maxPlayers": 10, "gameProperties": { "missionHeader": { "m_fMHT_myFloatVariable": 7, "m_bMHT_myBooleanVariable": true } }, "mods": [ { "modId": "5EAC510A8E6EC623", "name": "Mission Header Test" } ] } }
Hello there, issue should be internally fixed but not sure when exactly it will be released. Probably in some next major update.
I will keep the ticket open until it is released so be sure that there are no other issues afterwards,
Changes were made so that type in JSON is basically cast into script variables if possible.
Also note that Bool in script is internally int so false = 0, true = 1 and any value greater than 1 is still considered as true.
[Attribute(defvalue: "false")] bool m_BoolTest; [Attribute(defvalue: "22")] int m_IntTest; [Attribute(defvalue: "11.0")] float m_FloatTest; [Attribute(defvalue: "test")] string m_StringTest; [Attribute()] array<bool> m_BoolArrayTest; [Attribute()] array<int> m_IntArrayTest; [Attribute()] array<float> m_FloatArrayTest; [Attribute()] array<string> m_StringArrayTest;
"missionHeader": { "m_BoolTest": true, <---- boolean should now work "m_IntTest": 7.5, <---- float will be casted into int which should result in 7 "m_FloatTest": 2, <---- int will be casted into float "m_StringTest": "abc", "m_BoolArrayTest" : [ <---- works even in arrays with combined types 2, true, false, 5.5, 0 ], "m_IntArrayTest" : [ 2, true, false, 5.5, 0 ], "m_FloatArrayTest" : [ 2, true, false, "abc", <-------- this is invalid type 5.5, 0 ], "m_StringArrayTest" : [ "a", "b", "c" ] }
BACKEND (W): Server Config MissionHeader: Item on index 3 in parameter 'm_FloatArrayTest' is invalid type! SCRIPT : m_BoolTest : 1 <---- true SCRIPT : m_IntTest : 7 SCRIPT : m_FloatTest : 2 SCRIPT : m_StringTest : abc SCRIPT : m_BoolArrayTest : 0x0000023D1B191290 {2,1,0,5,0} <--- true, true, false, true, false SCRIPT : m_IntArrayTest : 0x0000023D1B191258 {2,1,0,5,0} SCRIPT : m_FloatArrayTest : 0x0000023D1B191220 {2,1,0,5.5,0} SCRIPT : m_StringArrayTest : 0x0000023D1B1911E8 {a,b,c}
Thanks for the reply. Looks promising!
Changes were made so that type in JSON is basically cast into script variables if possible.
Does this mean that parsing for other types that defvalue supports will also work?
Like "VETERAN" for EAISkill or "0 1 0" for vector or "0 1 0 1" for Color?