A couple more "quick" inquiries

Well, in that case, I'd honestly go with what I do for Holo, except I'd check for eligible Desert plots instead of looking for resources.

At least within the context of a normal game, a Grasslands plot will never suddenly change into a Desert plot, nor will a Desert plot ever suddenly stop being a Desert plot.

Leverage this with the occasions where plot ownership changed that I mentioned before, and it's not too bad -- Whenever border expansion / takeover occurs, scan those plots.

If a plot is found to be owned by the player, and is Desert, is Hills, has a Mine (and probably filter out mountains), add it to a master table of eligible plots.

Then, instead of scanning all the plots across the entire map every turn, simply have your function refer to this table and scan those specific plots instead. Remove plots from this table whenever they no longer meet eligible criteria (no longer owned by the player / anyone, or if it already has been granted a resource, etc.)

This way you distribute the load of plot scanning, and have a much more focused "list" of plots that your functions check through, instead of blindly scanning the entire map.

(For what it's worth, this is exactly something that will be coming in Holo's next version, as her Debau [or Tyler, haven't decided yet] Company HQ building will have a chance of granting nearby mines a mine-able resource. It's focused around a City though, instead of anywhere in her territory, but the method should be the same.)
 
Is there really an event hook that fires when a new tile is acquired?
(And does it work with G&K?)
 
Personally, I just scan a 3-tile radius around every City each turn, but this was before the last patch.

Lucky for you, the last patch brought in a few of the methods from whoward's DLL, including GameEvents.CityBoughtPlot which should work in G&K/Vanilla as well.

There's a bug with the version of the code Firaxis copied though, but for Culture-buying (which is how the City naturally expands) it will return the coordinates of the newly acquired plot. Unfortunately, the bug is that if you manually purchase a plot with Gold, the coordinates returned are incorrect -- they are the coordinates of the City that bought it.

Refer to this thread:
(Hook) GameEvents.CityBoughtPlot(ownerId, cityId, plotX, plotY, bGold, bFaithOrCulture);
 
So... in the case of a city being lost or gained in war, or a city being destroyed, how is it determined which plots belong to that city? Is there some City.GetPlots() method that I missed that will find which plots are owned by a particular city? Or will it simply require looping over the surrounding plots radius-style, which would be inaccurate?
 
Plots which belong to a City normally only falls within the 3-tile working radius of said City.
You can typically use pCity:GetNumCityPlots() in order to set up a for loop, but in my testing, it's basically identical to using whoward's spiral iterator with specific settings.

For all of my needs, I simply loop through the 36 plots around the City, and check for the plot owner before proceeding. It's still sort of brute-force-ish, but it's far less demanding than scanning the entire map every time.
 
So, for when a city is destroyed, I would use Events.SerialEventCityDestroyed? Does that actually work for anything besides UI?
And I'm assuming I would need to save tPlayerPlots with TableSaverLoader? I tried reading on how it works and, blatantly, did not understand it at all. Like, is TableLoad used to load the table or the game itself? What's gT? :crazyeye:
 
I don't know if that event ever fired for me when I was trying to test it (otherwise I would have used it, because I also need to be able to track plots being lost when a City is razed.) Even so, I don't usually trust Events to fire for the AI, so I limit myself to GameEvents. I don't know if there's any handy list of which Events behave like GameEvents whereby they reliably fire for an AI.

How I handled it with Holo is that since I track and store every plot I've altered into a table, when my function runs to scan that table each turn, if the stored plot is no longer owned by anyone, it means that a City was razed, and I execute the functions to undo any sort of bonuses I applied to it.

As for TSL, I'm not entirely sure how your code will turn out, so I'm not necessarily sure whether it's required or not, but if you do need to persist data through game saves, then TSL is a great option. You can also use SaveUtils if it might be simpler for you, although I feel it's more limiting, and annoying to litter save() and load() all over the code.

If you do end up using TSL, I recommend combining it with my TSL Serializer component (link in my sig) as it'll provide you two major benefits:

If your mod is not a total conversion, and is meant to be played with other mods, then it will assure compatibility with other mods which utilize TSL (and my Serializer.)

If you are new to adding TSL support, my Serializer also bundles the majority of the hookup code internally, so it's much simpler than following Pazyryk's original instructions. All you will need to do is toss the files in, follow the couple instructions I have, and create some way to run TableLoad() once somewhere in your script. After that, everything is more or less automatic, so long as you are able to handle a standard Lua table.

gT is Pazyryk's example of a global table used for storage of data that will be saved into the savegame database via TSL. You don't necessarily need to choose that name, and I wholeheartedy advise against usage of MapModData.gT because other modders might be using that as the default table simultaneously and cause issues.

Feel free to check my Serializer thread for a step-by-step installation example, as I had to write one up to guide JFD through it as well. Let me know if you still don't understand it.
 
Eh... it's still not making a whole lot of sense, but here's what I've gathered from it:
Code:
t_AW_PlotOwnerFunctionsTable = {}
tPlayerPlots = t_AW_PlotOwnerFunctionsTable.tPlayerPlots

include("TableSaverLoader016.lua")

tableRoot = t_AW_PlotOwnerFunctionsTable
tableName = "AW_PlotOwnerFunctions"

include("TSLSerializerV2_AW_PlotOwnerFunctions.lua")

function OnModLoaded()
	local bNewGame = not TableLoad(gT, tableName)
		if bNewGame then
		print("New Game")
		else print("Loaded from Saved Game")
		gLoadFromSave = 1
	end
	TableSave(gT, TableName)
end
Kind of a bunch of copy-pasting from throughout the thread and changing names. The name, incidentally, of the utility file I'm using to calculate the table is called PlotOwnerFunctions, which I plan to use, upon finishing it, to use for every civ of mine that needs to iterate over player-owned plots.

So these 20 lines should be placed at the top of PlotOwnerFunctions?
And then to save the table... well, just use TableSave(), it sounds like.

Or maybe I completely misunderstood. Which doesn't surprise me, really.

As for TSL versus SaveUtils... I actually was going to use TSL because I didn't know SaveUtils could handle tables. So what's the advantage of using TSL? That it can handle more tables being saved, or...? I'm honestly not seeing the benefit here.

------

As an aside, I started wondering how helpful it would be to other people if I compiled an index of mods most commonly and most helpfully given compatibility for, and how one goes about adding compatibility. A step-by-step tutorial of how to make E&D support and CulDiv and SaveUtils and so forth... or if everyone else already knows and really wouldn't help at all, or if it's mostly me that needs the index most of all. But I think it could make a handy reference. Any opinion about that?


Oh, and this thread should be renamed to "DarkScythe tutors AW", since that's effectively what it's turned into. :lol:
 
Eh... it's still not making a whole lot of sense, but here's what I've gathered from it:

Well then, time to try and explain everything, haha.

Code:
t_AW_PlotOwnerFunctionsTable = {}
[COLOR="Red"]tPlayerPlots = t_AW_PlotOwnerFunctionsTable.tPlayerPlots[/COLOR]

include("TableSaverLoader016.lua")

tableRoot = t_AW_PlotOwnerFunctionsTable
tableName = "AW_PlotOwnerFunctions"

include("TSLSerializerV2_AW_PlotOwnerFunctions.lua")

function OnModLoaded()
	[COLOR="Red"]local bNewGame = not TableLoad(gT, tableName)[/COLOR]
		if bNewGame then
		print("New Game")
		else print("Loaded from Saved Game")
		[COLOR="Red"]gLoadFromSave = 1[/COLOR]
	end
	[COLOR="Red"]TableSave(gT, TableName)[/COLOR]
end

I've highlighted in red the various areas that will cause problems. The basic order of the hookups looks fine, though, so I'll get that out of the way.

First up, you've defined what I assume will be your global data storage table, called t_AW_PlotOwnerFunctionsTable which is fine.

However, in the next line, you define a new variable called tPlayerPlots to what you hope to be a subtable underneath the aforementioned master table. The problem is... when have you defined any such subtable? You haven't defined it at all, much less being a table -- in this case its value is still nil. You've essentially told Lua to go look for t_AW_PlotOwnerFunctionsTable.tPlayerPlots, which doesn't exist, and to give that value (nil) to the variable tPlayerPlots.

This is essentially the same mistake I pointed out earlier; You need to define t_AW_PlotOwnerFunctionsTable.tPlayerPlots = {} before you can then rig a new reference to this subtable. This tells Lua to make a new, empty table with the index value of "tPlayerPlots" inside your master table. Only at this point can you start making new references to this, because then Lua will actually find something here (an empty table, which is better than nil.)

After that, the next few lines are fine -- including TSL itself, defining the tableRoot and tableName properly, and then including a renamed version of the TSL Serializer client file. At this point, you've gotten TSL save operations working (assuming that invalid subtable reference didn't yet blow anything up.) I should also point out that you should be using V3 of my Serializer, and not V2 -- V2 has a bug with savegame hotkeys, and is now unsupported.

However, the next part is presumably copied from LeeS' code example that I had posted, but there are many areas where you've not altered properly.

First, you need to call TableLoad(), which is fine because that's what it does -- the problem is it doesn't load the table you just defined! You just told TSL to load a table called gT even though your master table is supposed to be t_AW_PlotOwnerFunctionsTable. However, this is precisely why I advocate using the tableRoot variable I have everyone define, so replacing it with TableLoad(tableRoot, tableName) will work -- if at any point your master table changes, simply change the tableRoot definition, and everything else switches over automatically.

The next bit looks like a boolean from LeeS' code, which you likely don't need in here.

Finally, that TableSave() operation runs into the same problem as the TableLoad() -- it's not trying to save your master table, but something called gT, which in your case is undefined.

After all that, you still need to actually call OnModLoaded() somewhere in your Lua, or else this function never fires, and your tables are never loaded. The best place to put this would be after your code finishes preparing the table structure, and before the player gains control of the game.

Kind of a bunch of copy-pasting from throughout the thread and changing names. The name, incidentally, of the utility file I'm using to calculate the table is called PlotOwnerFunctions, which I plan to use, upon finishing it, to use for every civ of mine that needs to iterate over player-owned plots.

So these 20 lines should be placed at the top of PlotOwnerFunctions?

Do try and be more careful when you're copying and pasting, although at least you do admit as much, haha.

Otherwise, no, I would not recommend sticking the TSL Serializer stuff in such a "common/shared utility" component. The reason is that Pazyryk's TSL expects each instance of TableSave() to come from a unique Lua context. I've technically tested firing off an all-context-save from one single context and Lua call, but as he's recommended against doing so in his TSL documentation, I reworked my Serializer to try and ensure that each save call comes from each mod's own Lua context.

If you're confused, think of "each Lua context" as "each mod's own sandbox." My mod's Lua cannot, and should not be interfering with your mod's Lua, normally.

Because of this, and the way the game seems to handle duplicates found within its VFS system, including my Serializer within a 'common component' like that could muck with the Lua contexts that the TableSave() calls originate from. You should leave the TSL stuff in whatever your "main" Lua file is, and simply include your plot functions file afterward separately. If you still insist on doing so though, at least in my limited testing, it seemed to handle it okay, but I can't guarantee you won't run into obscure problems.

And then to save the table... well, just use TableSave(), it sounds like.
You shouldn't need to touch anything to do with TableSave() once you've included my Serializer properly. Only in very specific circumstances would you need to considering adding a manual TableSave() call somewhere, though depending on what it's for, you may be better off using my Serializer's replacement LuaEvents.TSLTableSave() so that you can notify all other contexts/mods to save their TSL data at the same time.

Otherwise, with the Serializer installed, it will automatically handle the saving of data on autosaves, game saves through the menu, quick saves through the menu, game saves with the Ctrl+S hotkeys, and quick saves with the F11 hotkey.

As for TSL versus SaveUtils... I actually was going to use TSL because I didn't know SaveUtils could handle tables. So what's the advantage of using TSL? That it can handle more tables being saved, or...? I'm honestly not seeing the benefit here.
I decided to use TSL mainly because it felt a lot more flexible and powerful, allowing easy transition into more complex data storage without having to re-engineer the code if I ever switched. The other thing is that, at the time I looked it up, SaveUtils was already abandoned and technically in danger of obsolescence because of its reliance on SetScriptData() or something to that extent.

It also had the bonuses on the coding side of not having to put save() and load() everywhere in the code when I needed to change something, which helps immensely with code clutter, and being able to address all of my data using standard Lua table manipulation allows me to work with it very easily as it basically sits invisibly in the code acting essentially as any other Lua table. No new syntax to learn is very welcome for me here, although at the time I didn't know much at all about how tables worked anyway.

The "abandoned" issue is also slightly less of an issue now since Pazyryk himself has not been around in a while, and I think sukritact has some sort of modified/updated version of SaveUtils somewhere.

The only upside I see to SaveUtils is that it's much simpler. Because you have to manually call the save() and load() each time, there's no "hookup code" beyond defining your mod name and such. I still feel the few minutes of setting up TSL pays off in the long run of having it be fully automatic in this respect, though.

As an aside, I started wondering how helpful it would be to other people if I compiled an index of mods most commonly and most helpfully given compatibility for, and how one goes about adding compatibility. A step-by-step tutorial of how to make E&D support and CulDiv and SaveUtils and so forth... or if everyone else already knows and really wouldn't help at all, or if it's mostly me that needs the index most of all. But I think it could make a handy reference. Any opinion about that?

I suppose it wouldn't be a bad idea, but each of those typically has detailed instructions in their own threads already. I feel it would be less a guide and more just an index of mod components. I have no real opinion one way or the other on that point, though. I'll leave it to others to decide here.

Oh, and this thread should be renamed to "DarkScythe tutors AW", since that's effectively what it's turned into. :lol:
That would be quite a lot of pressure there, since I don't really know everything, haha.
 
Then, I suppose the next draft would look like such:
Code:
t_AW_PlotOwnerFunctionsTable = {}
t_AW_PlotOwnerFunctionsTable.tPlayerPlots = {}
tPlayerPlots = t_AW_PlotOwnerFunctionsTable.tPlayerPlots

include("TableSaverLoader016.lua")

tableRoot = t_AW_PlotOwnerFunctionsTable
tableName = "AW_PlotOwnerFunctions"

include("TSLSerializerV2_AW_PlotOwnerFunctions.lua")

function OnModLoaded()
	local bNewGame = not TableLoad(tableRoot, tableName)
		if bNewGame then
		print("New Game")
		else print("Loaded from Saved Game")
	end
	TableSave(tableRoot, TableName)
end
However... if putting TSL in a utility would make the file have compatibility problems with itself, wouldn't SaveUtils have an advantage? After all, since the point of the utility is to be haphazardly included in each necessitating mod without any necessary alteration, the file could be saving and loading to and from the same keys, so that seems like it would have less of a compatibility problem.

But say I did use TSL. So the TSL should then be at the top of the file that includes PlotOwnerFunctions? And thus TSL would need to be given compatibility for... what, every file that needs it? Or just once per mod?
That would be quite a lot of pressure there, since I don't really know everything, haha.
You wouldn't be the first to claim that, either. Pretty much anyone who's had to walk me through stuff (which... is basically you, VV and bane_, probably because you have the most amazing patience (although, as you said once, tutoring at an elementary school helps (and don't ask how I remember that (let's embed more parantheses just for the heck of it!)))) has then subsequently claimed that they don't know anything, despite that they clearly understand it much better than me.
 
Phew, okay. Sorry for the delay, but that took a while to look through the SaveUtils code and try to figure it out.

As far as your currently-proposed TSL+Serializer hookup code goes, it looks fine except for two things:
  1. Use Serializer V3, instead of V2 (though technically the filename doesn't matter as long as the contents are that of V3, but I figured I'd remind you.)
  2. You still need to call OnModLoaded() somewhere; Defining the function doesn't do anything if you never actually run it.

With that said, on to your (fairly loaded) questions...

Putting TSL in such a "common/shared" utility component does not in and of itself cause compatibility problems. As I've stated, I did successfully test using TSL to fire off an all-context save from within a single context. However, the reason I've separated it is because of Pazyryk's documentation recommending against doing so -- it's his code, so I'm not going to argue with that.

In this case, I cannot answer with 100% certainty, because I've never actually used SaveUtils, but from my interpretation of the code, it attempts to do something very similar in terms of handling multiple contexts. Taken from the very top of SaveUtils' instructions:

To use this file, place the following line of code in your modded file's
global scope and set your mod's unique name.

include( "SaveUtils" ); MY_MOD_NAME = "MyMod";

Emphasis has been placed by me in the relevant bits.

What I gather is that SaveUtils wants to be able to differentiate between the various pieces of data being saved by different mods. This plays into the whole Lua contexts thing that I described before, and you can still think of them as sandboxes in terms of separation.

Let's go with a simple example:
You have a mod which will want to save data about pPlayer, so you fire off a save() command. You can now retrieve the data in pPlayer whenever you want by issuing a load() command. This is fine, because you're in your own sandbox, but even if you weren't, you're currently the only one there anyway.

Now let's have my hypothetical mod enter the scene. Right after you've saved the details about pPlayer, my mod decides it wants to save details about a different pPlayer. You would expect that this should be fine, because we're each in our own sandboxes (contexts,) and normally, this is fine.

However, remember how you needed to implement SaveUtils: MY_MOD_NAME = "MyMod";

If both of our mods decided to use the same MyMod name, then to SaveUtils, we're both trying to save the same piece of information into the same place. This should result in the data from my mod's pPlayer replacing yours, and when you go to load it, it's not what your code expects, even though we're supposed to be in separate sandboxes!

If you load SaveUtils (or any of these utilities for that matter) then you're effectively tying all of these separated sandboxes together inadvertently, because you can only specify a single "name" or instance of save data.

I should point out that this is merely my assumption of how SaveUtils will function in this scenario, again since I've never actually used it myself.

TSL I think has its own reasons for wanting to be in each mod's own contexts as well.

SaveUtils also has the downside of relying on SetScriptData() of which I believe only works on a handful of object types (Plot and Player I think?) but it has been removed from other objects already.

There exists some sort of NewSaveUtils which works on the same basic principle as TSL, using Modding.OpenSaveData() in order to access the savegame database.

Along that vein, sukritact also appears to have written his own variation of NewSaveUtils, dubbed Sukritact_SaveUtils which also appears to function on the premise of using the savegame database.

Of these three versions, I can only imagine that Sukritact may have built in checks or something with regard to handling data coming from multiple contexts since he uses it as part of his Events & Decisions mod, but even then I don't really see where such a check occurs (the code references the same MY_MOD_NAME variable.) As well, I believe E&D is a standalone mod to begin with, so even then his SaveUtils is not necessarily operating over multiple contexts.

Much of this is conjecture on my part after reviewing the code though, so if I got something wrong and sukritact sees this, I'd appreciate any corrections.

With all that said, I don't agree with this conclusion you've reached:
since the point of the utility is to be haphazardly included in each necessitating mod without any necessary alteration

Each one of these utilities has to be called into each mod, and at the very least "set up" with some sort of identifier. It just so happens that SaveUtils' set-up is shorter and simpler than TSL, though I've taken care with my Serializer to make it as simple a process as possible (I mean, it's two variables and an include, versus one variable and an include; only step I really left out was how to call TableLoad() since that can vary.)

As far as where to put TSL, if you're doing it according to the instructions, it only needs to be included and set up in your mod's main Lua file once, and it will operate to save all the data in that particular mod/context.

Again, trying to place TSL into a shared component like Plot Iterators would likely cause you to run into the above issue of unintentionally linking various Lua contexts together.

In the end, it's up to you which utility you want to use, and if you want to use one of the versions of SaveUtils, you are free to do so. However, I do stand by my assertion that, to me at least, I find it vastly easier and cleaner to simply set aside on table, and work everything off that one Lua table, rather than having to define save() and load() everywhere, especially since you need to specify multiple arguments to save().

It will also be extremely YMMV if you try to go ahead with putting the data persistence utilities in your shared Plot Iterators file.

It may work, or it may explode; I honestly have no idea, and can't say anything other than it probably might work, but these utilities were also not (in my eyes) designed to operate in that scenario.
 
Alright, let's necro again and veer this thread in another entirely different direction!

Two questions, and I promise they're simple (?) and short:

1) What's the difference between City.GetReligiousMajority() and City.GetFavoredReligion()?

2) How finds one a civ's majority religion? That is, the religion practiced in most of a player's cities, since this doesn't seem to exist as a built-in function according to the lua/ui reference...
 
How about this: why do leaderscenes show up black? :p I'm playing a game against my Taiwanese civ right now and I can't for the life of me figure out why the leaderscene is showing up black. I checked load attributes, contents of the scene XML, made sure all the file references were typed in correctly and even made sure the DDS was the right size - but no dice.

If it helps, this is the most recent version, complete with a few changes I made directly to the files that aren't found in the version downloadable from the forums.
 
Black leader scene usually means that your scene DDS has no Alpha layer saved.

Double-check your DDS file, as I see no Alpha channel when loading it up.
 
Yep, that fixed it, thanks. No idea why sometimes Gimp chooses to automatically add an alpha layer and sometimes it doesn't though...
 
So, I'm far enough along into the development process of one of my mods that I need to start worrying about TSL again...

So we've already gone over the PlotOwner_Function TSL Serializer code and all that. Now I've run into another problem that I don't remember if it was already answered or not:

There's another file in the mod - UI_Functions, since it controls the civ's UI - that depends on PlotOwner_Functions, the file that allows iterating over all of a player's plots. (Although, it may not be necessary after all, at least for this mod). It has a similar situation in that it controls a table of plots that also needs to be saved. Do I put the same whole TSL Serializer code at the top of that to save another table that, unlike tPlayerPlots from PlotOwner_Functions, is not going to be used in a utility?
(I hope that made sense...)

And PlotOwner_Functions, as it turns out, depends on four other utility files (!) to function. (3 of them are TSL-related :p) Now that it's all set up, can I just copy and paste all 5 of the files into whatever mod I need, or does the TSL Serializer client file need to be edited for each separate mod using it?

I get the feeling that I may not be making any sense here...


EDIT: Okay, let's simplify that question by quite a bit: Can one core file manage several client files, and do I need a client file for every file with a table to be saved?
 
Okay... I still think I'm not making sense, and it's not making sense to me, so let me try this TSL Serializer thing another way...

I've got two separate files that each need one table saved - We'll call them tX and tY, which are found in files x.lua and y.lua, respectively. I don't know if a single core file is allowed to manage several client files, so I decided to make a new file that will do nothing but hook up the TSL Serializer, which includes x.lua and y.lua in order to gain access to tX and tY.
The code essentially looks like this:
Spoiler :
Code:
---------------------------------------------
------------ TSL SERIALIZER CODE ------------
---------------------------------------------

include('x.lua')
include('y.lua')

t_AW_Stuff_Table = {}
t_AW_Stuff_Table.tX = tX -- from x.lua
t_AW_Stuff_Table.tY = tY -- from y.lua

include("TableSaverLoader016.lua")

tableRoot = t_AW_Stuff_Table
tableName = "AW_Stuff_Table"

include("TSLSerializerV3_AW_Stuff.lua")

function OnModLoaded()
	local bNewGame = not TableLoad(tableRoot, tableName)
		if bNewGame then
		print("New Game")
		else print("Loaded from Saved Game")
	end
	TableSave(tableRoot, TableName)
end

OnModLoaded()
I figured that this part from PlotOwner_Functions:
Code:
t_AW_PlotOwnerFunctionsTable.tPlayerPlots = {}
tPlayerPlots = t_AW_PlotOwnerFunctionsTable.tPlayerPlots
would be a problem, since it's actually creating a table, whereas in the new example I already have the tables tX and tY set up (albeit in other files), and am just plugging them into the new parent table, t_AW_Stuff_Table.
I didn't see anything in the TSL Serializer instructions dictating whether or not one core file can manage several client files, which is why I had to try this convoluted way.

Bueno or no bueno?
I still don't understand plz don't hit me
 
And also this:
Code:
[37942.875] Runtime Error: C:\Users\AW\Documents\My Games\Sid Meier's Civilization 5\MODS\AW's [REDACTED] Mod (v 1)\Lua/[REDACTED]_Functions.lua:103: attempt to index a function value
Code:
if not (GameInfo.Unit_Builds{UnitType=GameInfo.Units[pUnit:GetUnitType()].Type}.BuildType == GameInfoTypes.BUILD_AW_SECRETSECRECY) then return end
This has already been answered but I still can't figure out what I'm doing wrong here. :lol: Essentially this should check that pUnit can build AW_SECRETSECRECY, so that I'm not being close-minded and only checking workers. :p

That is the result of today's debugging session. Not bad for my first lua-debugging day for this mod :D
 
Compare this:
Code:
if not (GameInfo.Unit_Builds{UnitType=GameInfo.Units[pUnit:GetUnitType()].Type}.BuildType == GameInfoTypes.BUILD_AW_SECRETSECRECY) then return end
To this:
Code:
local freeUnitDetails = GameInfo.Units{ID=iFreeUnit}()
sRequiredCombatClass = freeUnitDetails.CombatClass
sRequiredUnitDomain = freeUnitDetails.Domain
Or this
Code:
GameInfo.Units[iUnitToSpawn].Type
Then compare to this:
Code:
	<Table name="Unit_Builds">
		<Column name="UnitType" type="text" reference="Units(Type)"/>
		<Column name="BuildType" type="text" reference="Builds(Type)"/>
	</Table>
Assume for a moment that this:
Code:
GameInfo.Unit_Builds{UnitType=GameInfo.Units[pUnit:GetUnitType()].Type}.BuildType
works properly and gets you the one and only BuildType from within the table <Unit_Builds> that pertains to the specified pUnit. What do you have in the lefthand portion of the equation?

You have a text string. IE, something along the order of "BUILD_ROAD". You are trying to compare a text string to an integer that will be on the right-hand side of the ==. Instant code failure.

I am not even sure you are making it that far because I am not sure this:
Code:
GameInfo.Unit_Builds{UnitType=GameInfo.Units[pUnit:GetUnitType()].Type}.BuildType
is not inherently flawed because Unit_Builds does not have ID and Type columns. It might work with such a construction for a table without ID and Type but I've never tried it under the assumption it wouldn't work properly (the potential would be to get multiple 'answers' to that construction when pUnit is referencing for example a worker because there are multiple rows in the table that all match for UNIT_WORKER).

----------------------------------------------------------------------------

edit


looking back through some of my earlier code for some of my mods, see this
Code:
sRequiredCombatClass = GameInfo.Units{ID=iFreeUnit}[B][COLOR="Blue"]()[/COLOR][/B].CombatClass
I think this is the direct reason why you are getting the error you are getting. You still have the text -> integer comparison issue.

So I think what you would need to get it to work (assuming it works to pull the BuildType out of an individual row in the manner you are trying) would be:
Code:
GameInfo.Unit_Builds{UnitType=GameInfo.Units[pUnit:GetUnitType()].Type}[B][COLOR="Blue"]()[/COLOR][/B].BuildType
And then you would have to GameInfoTypes the result of all that in order to get an integer -> integer comparison.
 
I drew an overly complicated diagram to figure this out...
Would it be:
Code:
if not (GameInfo.Builds{Type=GameInfo.Unit_Builds{UnitType=GameInfo.Units{ID=pUnit:GetUnitType()}.Type}.ID == GameInfoTypes.BUILD_AW_SECRETSECRECY) then return end
This way I'm at least comparing two variables of the same type, although I may have missed a logical step here somewhere...
And also maybe function calls. Do I need more parens?
 
Back
Top Bottom