Advertisement
Civilization Fanatics' Center  

Welcome to Civilization Fanatics' Center.

You are currently viewing our site as a guest which gives you limited access to our site features. By joining our free community, you will be able to participate in the discussions, search the forum, send private messages, vote in polls, upload your own screenshots to the gallery, and access many other special features. Registration is fast, simple and absolutely free, so sign up today! If you have any problems with the registration process or your account login, please contact support.

Go Back   Civilization Fanatics' Forums > CIVILIZATION V > Civ5 - Creation & Customization > Civ5 - SDK / LUA

Notices

Reply
 
Thread Tools
Old Aug 20, 2011, 06:07 PM   #1
Thalassicus
Bytes and Nibblers
 
Thalassicus's Avatar
 
Join Date: Nov 2005
Location: Texas
Posts: 10,263
Question Save and Load

I've got this algorithm:

PHP Code:
local milRewardCurrent = (LoadPlayer(player"milRewardCurrent") or 0) + 1
log
:Error("%25s %15s current=%i threshold=%i""GiveMilitaristicRewards"player:GetName(), milRewardCurrentmilRewardThreshold)

if 
milRewardCurrent >= milRewardThreshold then
  milRewardCurrent 
milRewardCurrent milRewardThreshold

  
-- give a free unit (no more interaction with the milReward variables)
end

SavePlayer
(player"milRewardCurrent"milRewardCurrent
PHP Code:
function LoadPlayer(playerkey)
  return 
saveDB.GetValue(string.format("%s_player%s_%s"MOD_IDplayer:GetID(), key))
end

function SavePlayer(playerkeyvalue)
  return 
saveDB.SetValue(string.format("%s_player%s_%s"MOD_IDplayer:GetID(), key), value)
end 
Some output:
Code:
ERROR GiveMilitaristicRewards Montezuma current=11 threshold=10
(free unit)
ERROR GiveMilitaristicRewards Montezuma current=11 threshold=10
(free unit)
How is it possible to not reset the current value? Here's the full text:
Spoiler:
PHP Code:
local milRewardThreshold UnofficialPatch.MINOR_CIV_MILITARISTIC_BASE_TURNS rateMod
      milRewardThreshold 
milRewardThreshold GameInfo.GameSpeeds[Game.GetGameSpeedType()].TrainPercent 100
local milRewardCurrent 
= (LoadPlayer(player"milRewardCurrent") or 0) + 1
log
:Error("%25s %15s current=%i threshold=%i new=%i""GiveMilitaristicRewards"player:GetName(), milRewardCurrentmilRewardThresholdmilRewardCurrent milRewardThreshold)
if 
milRewardCurrent >= milRewardThreshold then
  milRewardCurrent 
milRewardCurrent milRewardThreshold
  local availableIDs  
GetAvailableUnitIDs(capitalCity)
  
local newUnitID     availableIDs[Map.Rand(#availableIDs, "InitUnitFromList")]
  
local capitalPlot   capitalCity:Plot()
  
local xp            GetCitystateYields(playerMinorCivTraitTypes.MINOR_CIV_TRAIT_MILITARISTIC2)[YieldTypes.YIELD_EXPERIENCE].Total

  
if GameInfo.Units[newUnitID].Domain ~= "DOMAIN_LAND" then
    xp 
xp UnofficialPatch.MINOR_CIV_MILITARISTIC_XP_NONLAND_PENALTY
  end

  log
:Debug("  Reward=%s  XP=%s"GameInfo.Units[newUnitID].Typexp)
  
local newUnit M_InitUnit(playernewUnitIDcapitalPlotxp)

  
local promotion GetTrait(player).MilitaristicCSFreePromotion

  
if promotion then
    newUnit
:SetHasPromotion(GameInfo.UnitPromotions[promotion].IDtrue)
  
end
  

  local newUnitInfo 
GameInfo.Units[newUnitID]
  if 
Game.GetActivePlayer() == player:GetID() then
    local newUnitIcon 
= {{"Unit1"newUnitID000}}
    
local newUnitName Locale.ConvertTextKey(newUnitInfo.Description)
    
CustomNotification(
      
"RewardMilitaristic",
      
"New "..newUnitName,
      
"A new "..newUnitName.." arrived in your [ICON_CAPITAL] Capital from your militaristic [ICON_CITY_STATE] City-State allies.",
      
capitalPlot,
      
0,
      
0,
      
newUnitIcon
    
)
  
end
end
SavePlayer
(player"milRewardCurrent"milRewardCurrent
__________________

We are the Modders. CiV will be assimilated.
We will enhance its biological and technological distinctiveness with our own.
Resistance is futile.


Communitas Expansion Pack
Wiki - Discussion - News


Forum Icons ~ Starting Civ5 Mods ~ Forum Tables

Last edited by Thalassicus; Aug 20, 2011 at 06:15 PM.
Thalassicus is offline   Reply With Quote
Old Aug 23, 2011, 03:00 AM   #2
Sengir
Deity
 
Join Date: Oct 2004
Posts: 2,379
I don't have access to your files (and just starting with modding), but spamming more debug-code might help in this case. As far as I can tell the code you posted is correct, but I'm not a LUA-specialist so might be wrong. To verify I'd log the value of 'milRewardCurrent' just before calling SavePlayer(player, "milRewardCurrent", milRewardCurrent), to test whether SavePlayer gets the right value.

If that's ok, then log the value of 'value' inside SavePlayer. If that is also correct, the problem seems to be inside SaveDB.setValue


EDIT: Just to be sure: is the bug consistent?
__________________
Never argue with dumb people, they take you down to their level and beat you with experience.
FAQs Are Bugs You Haven’t Fixed Yet [Drew McLellan]

Last edited by Sengir; Aug 23, 2011 at 04:02 AM.
Sengir is offline   Reply With Quote
Old Aug 23, 2011, 05:52 AM   #3
Sengir
Deity
 
Join Date: Oct 2004
Posts: 2,379
Tried it myself by loading your mod, but I can't reproduce it. Do you have a save or a sure-fire way to make it happen?
__________________
Never argue with dumb people, they take you down to their level and beat you with experience.
FAQs Are Bugs You Haven’t Fixed Yet [Drew McLellan]
Sengir is offline   Reply With Quote
Old Aug 23, 2011, 08:10 AM   #4
Thalassicus
Bytes and Nibblers
 
Thalassicus's Avatar
 
Join Date: Nov 2005
Location: Texas
Posts: 10,263
I haven't been able to replicate the problem; I'm going off a bug report of a user of the mod. It might be there's some secondary problem causing this one, though it's strange it could happen at all... the algorithm seems straightforward. I guess if people keep reporting this bug I'll investigate further.
__________________

We are the Modders. CiV will be assimilated.
We will enhance its biological and technological distinctiveness with our own.
Resistance is futile.


Communitas Expansion Pack
Wiki - Discussion - News


Forum Icons ~ Starting Civ5 Mods ~ Forum Tables
Thalassicus is offline   Reply With Quote
Old Aug 23, 2011, 08:48 AM   #5
Sengir
Deity
 
Join Date: Oct 2004
Posts: 2,379
Hmm, annoying. I suppose the user doesn't have a save either... It is indeed strange that it happens at all, that's why I'm annoyed at not being able to solve it
__________________
Never argue with dumb people, they take you down to their level and beat you with experience.
FAQs Are Bugs You Haven’t Fixed Yet [Drew McLellan]
Sengir is offline   Reply With Quote
Old Sep 26, 2012, 01:35 PM   #6
FramedArchitect
Warlord
 
Join Date: Mar 2012
Location: Missouri
Posts: 201
~Found your utilities...so question asked and answered~

Quote:
Originally Posted by Thalassicus View Post
local promotion = GetTrait(player).MilitaristicCSFreePromotion
Thal....love your VEM and the GK version looks very promising!

I hate to bug you with such niggling details, but I'm trying to pull player traits for a small mod, and I can't get your method above to work for me. I can't find a GetTrait player method in the API documentation. Is this a function you developed?

I tried your other trait pull method, which also doesn't work for me.

Code:
local trait = player:GetTraitInfo()
Any suggestions?

Last edited by FramedArchitect; Sep 26, 2012 at 04:00 PM.
FramedArchitect is offline   Reply With Quote
Old Sep 27, 2012, 06:42 AM   #7
DonQuiche
King
 
DonQuiche's Avatar
 
Join Date: May 2011
Posts: 943
Quote:
Originally Posted by FramedArchitect View Post
I can't find a GetTrait player method in the API documentation. Is this a function you developed?
There is no need for such a function in the API because the traits are static data and you can use GameInfo and such to retrieve them.

Player -> Civilization ID (through Player.GetCivilizationType) -> Civilization type (through GameInfo.Civilizations) -> Leader type (through GameInfo.Civilization_Leaders) -> all traits types (through GameInfo.Leader_Traits)

References:
* Lua and UI Reference (look at GameInfo especially)
* Civ5Cvilizations.xml
* Civ5LeadersTables.xml

Edit: err... The GameInfo content is missing... Well... I will fix this. Basically use things like
* GameInfo.Civilizations[civID].Type to get the type from the ID
* GameInfo.Civilization_Leaders{CivilizationType = civType}().LeaderType to get the first (and unique) leader for the given civtype.
__________________
Reseed! Preview and regenerate map in-game.
Ingame Editor (IGE): An in-game editor for terrain, units, cities, civilizations, etc.
Lua and UI reference

Last edited by DonQuiche; Sep 27, 2012 at 06:46 AM.
DonQuiche is offline   Reply With Quote
Old Sep 27, 2012, 10:23 AM   #8
FramedArchitect
Warlord
 
Join Date: Mar 2012
Location: Missouri
Posts: 201
Quote:
Originally Posted by DonQuiche View Post
There is no need for such a function in the API because the traits are static data and you can use GameInfo and such to retrieve them.
Thanks for the reply... I figured this out as in this thread. http://forums.civfanatics.com/showpo...4&postcount=66

Thal developed above utility to bypass this laborious linking.

Btw, love your IGE for its tuner logs.
FramedArchitect is offline   Reply With Quote
Reply

Bookmarks

Go Back Civilization Fanatics' Forums > CIVILIZATION V > Civ5 - Creation & Customization > Civ5 - SDK / LUA > Save and Load

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Advertisement

All times are GMT -6. The time now is 12:34 AM.


Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
This site is copyright © Civilization Fanatics' Center.
Support CFC: Amazon.com | Amazon UK | Amazon DE | Amazon CA | Amazon FR