[GS] GamePlay Script Lua file can't use GamePlay Script function but UI Context function is OK? Why?

Windflier

Chieftain
Joined
Dec 15, 2017
Messages
39
This is my Lua_ScriptSetUp.lua:
Code:
ExposedMembers.GameEvents = GameEvents;

function ChangeCityProduction(pCity,number)
    pCity:GetBuildQueue():AddProgress(number);
end

GameEvents.OnChangeCityProduction.Add(ChangeCityProduction)
And in modinfo, this file is imported as gameplay script:
Code:
    <AddGameplayScripts id="SetupLua">
      <Properties>
        <LoadOrder>98</LoadOrder>
      </Properties>
      <File>Lua_ScriptSetUp.lua</File>
    </AddGameplayScripts>
But when I test it, when the ChangeCityProduction function is being called, the Gamplay Script function such as AddProgress() fail, but the UI Context function such as GetCurrentGovernment works.
So my gameplay script file is registered as UI Context script? Why did this happen?

Also, I call this function in other UI Context script, this is where the ExposedMembers coming in place, I call this function in other UI Context script:
Code:
GameEvents = ExposedMembers.GameEvents;
GameEvents.OnChangeCityProduction.Call(pCity,10);
I wonder if this is the problem, if it is, then what's the solution?
 
Because you pass a city object taken from UI context, you need to pass the cityID and playerID then get the city object in the Gameplay context (eventually you could get the IDs from the object you've passed)
 
Because you pass a city object taken from UI context, you need to pass the cityID and playerID then get the city object in the Gameplay context (eventually you could get the IDs from the object you've passed)
So I need to pass the number instead of object to the function, thanks, now I know what's the problem!
 
Top Bottom