How to fix:
Change
x = "10.1 * ( ((safezoneW / safezoneH) min 1.2) / 40) + (call compile (profilenamespace getvariable [""IGUI_GRID_WEAPON_X"",str ( ((safezoneX + safezoneW) - (12.4 * ( ((safezoneW / safezoneH) min 1.2) / 40)) - 0.5 * ( ((safezoneW / safezoneH) min 1.2) / 40)))]))";
To
x = "with profileNamespace do {\
if (!isNil ""IGUI_GRID_WEAPON_X"") then [\
{10.1 * (((safezoneW / safezoneH) min 1.2) / 40) + IGUI_GRID_WEAPON_X},\
{((safezoneX + safezoneW) - (12.4 * (((safezoneW / safezoneH) min 1.2) / 40)) - 0.5 * (((safezoneW / safezoneH) min 1.2) / 40))}\
]\
}";
And not just here, everywhere! The above is tested and works just fine with dynamic class loading. Of course the value of IGUI_GRID_WEAPON_X is now SCALAR not STRING, but this is what we want anyway, right?