CivilizationAce
Warlord
- Joined
- Jan 17, 2017
- Messages
- 236
Code:
GameConfiguration.SetValue(key, fMissedChanceTotal)
Code:
function expected instead of nil
GameConfiguration.SetValue(key, fMissedChanceTotal)
function expected instead of nil
mean?SetValue is only available in UI
Finding this thorough discussion is not so simple. There are no messages with "context" in the title. There are next to no uses of the word "context" in the body of messages. I have looked at all Gedemon's messages that seem even slightly on topic and can find none that make it any clearer than mud, although it's possible that I have failed to find the correct message through a lack of clues. I've searched for "expose" and got onlythis topic has been thoroughly discussed
Basically, you either save data from within UI context or expose GameConfiguration.SetValue to other contexts.
I don't see anything in there that tells me how to define the type in either modbuddy or the .modinfo filethe part about the difference between UI/script context for lua files here (the type is defined in modbuddy or the .modinfo file)
https://forums.civfanatics.com/threads/information-from-firaxis-developer-on-the-mod-tools.611291/
function onSetValue(key, value).
print('onSetValue')
GameConfiguration.SetValue(key,value)
end
--function InitialiseUILua()
print('LuaEvents.SetValue.Add(onSetValue)')
LuaEvents.SetValue.Add(onSetValue)
--end
--Events.LoadScreenClose.Add(InitialiseUILua)
<Context>
<UserInterface FileName="UI_Scope" ID="UI_Scope"/>
</Context>
function onSetValue(key, value)
print('onSetValue')
print('key, value: '..key..', '..value)
GameConfiguration.SetValue(key,value);
print("After")
local recovered = GameConfiguration.GetValue(key)
print('recovered: '..recovered)
end
print('LuaEvents.SetValue.Add(onSetValue)')
LuaEvents.SetValue.Add(onSetValue)
function onCreateUnit(pPlayer, iUnitIndex, iX, iY)
print('pPlayer:GetID(), iUnitIndex, iX, iY: '..pPlayer:GetID()..', '..iUnitIndex..', '..iX..', '..iY)
pPlayer:GetUnits():Create(iUnitIndex, iX, iY)
print('After')
end
function OnLoadScreenCloseGameplay()
print('OnLoadScreenCloseGameplay start')
LuaEvents.CreateUnit.Add(onCreateUnit)
end
Events.LoadScreenClose.Add(OnLoadScreenCloseGameplay)
Not true apparently. I changed my code to check, not the context directly, but whether or not SetValue returns nil. I also added code to find at what point Create breaks:the consumption of an event adopts the context of where it was thrown
function onCreateUnit(pPlayer, iUnitIndex, iX, iY)
if GameConfiguration.SetValue then
print('GameConfiguration.SetValue true')
else
print('GameConfiguration.SetValue false')
print(GameConfiguration.SetValue)
end
print('pPlayer:GetID(), iUnitIndex, iX, iY: '..pPlayer:GetID()..', '..iUnitIndex..', '..iX..', '..iY)
if pPlayer:GetUnits().Create then
print('pPlayer:GetUnits().Create true')
else
print('pPlayer:GetUnits().Create false')
print(pPlayer:GetUnits().Create)
end
if pPlayer:GetUnits() then
print('pPlayer:GetUnits() true')
else
print('pPlayer:GetUnits() false')
print(pPlayer:GetUnits())
end
if pPlayer then
print('pPlayer true')
else
print('pPlayer false')
print(pPlayer)
end
pPlayer:GetUnits():Create(iUnitIndex, iX, iY)
print('After')
end
function OnLoadScreenCloseGameplay()
print('OnLoadScreenCloseGameplay start')
LuaEvents.CreateUnit.Add(onCreateUnit)
end
Events.LoadScreenClose.Add(OnLoadScreenCloseGameplay)
ForceSensitive_Gameplay: GameConfiguration.SetValue false
ForceSensitive_Gameplay: nil
ForceSensitive_Gameplay: pPlayer:GetID(), iUnitIndex, iX, iY: 0, 103, 6, 17
ForceSensitive_Gameplay: pPlayer:GetUnits().Create false
ForceSensitive_Gameplay: nil
ForceSensitive_Gameplay: pPlayer:GetUnits() true
ForceSensitive_Gameplay: pPlayer true