Lua table insert table
#Lua table insert table update#
You can update a table value the same way you update any variable:
#Lua table insert table how to#
Yeah, just stay away from table.insert until you really learn how to access and assign table values (then go back and use if if you want). I often name my tables so I know what they contain and what they are indexed by, for example "specialUnitTypeIDsB圜ivID" (I can remember that the index is an integer and not a type string).
#Lua table insert table code#
Unit, unitInfo are both tables (unit is the game object, which really is a table unitInfo in my code would refer to the table row from Units table, which is also a table) In my code, unitType, civType, etc are all strings (Firaxis is entirely inconsistent on this) IPlayer, playerID, unitTypeID, iPlot, etc are all integers! However, there is no reason that your variable name should ever lie about what it is: I don't bother using strict Hungarian notation. Local plotOwnerCivType = -string (= "CIVILIZATION_ZULU" or whatever) Local iPlotOwnerCiv = Players:GetCivilizationType() -integer Local iPlotOwner = plot:GetOwner() -integer (actually playerID) (As an aside: Lua tables can use anything other than nil as a key, including tables or functions, but don't do that unless you are feeling really cocky.) However, don't confuse yourself on which you are using: On the table side, Lua tables are happy using integers or strings for keys, or even both in the same table. I was editing post above with local/global stuff while you were posting, so take a 2nd look. I don't even know if the table can hold stuff like this, but in my imagination it would be like this: I can do all this, except the storing this number and editing it while linking it with the Civilization (in order to later identify it with ease). The whole idea is a button that creates a number and this number can be modified X times per turn, then cleaned at the start of your next turn, but if it reaches a certain number it fires a function, so I need to fire the mission/button, find the targeted Civilization, add the number there + the new number and then check to see if it matches or exceeds the target number. I thought that I could do that with that code up there, where k would be the civ and v the value I want - which would be easy to find, since Civilizations have unique names while the variable can be equal (although, after reading the code, it seems I did it backwards).
I want to store information on both a Civilization and a variable that CAN change, so I'll need to change it within the table too, which means I need to always know it's position. I believe I understood you perfectly, which is a bit worrisome for me or you are just that good at explaining things - you should join forces with JFD. Return A = U) luaL_error (L, " invalid function for Sorting Order " ) Storage lua string and C are not the same, the lua each string is a single copy, splice two strings will produce a new copy, particularly if the splicing operation, will affect the performance of (By injection: the string operation, must be avoided.
concat table array portion may be spliced into a single string, separated by seq.
1 end end - correctly, to control their own whether to increase the value of iĢ.