• Our friends from AlphaCentauri2.info are in need of technical assistance. If you have experience with the LAMP stack and some hours to spare, please help them out and post here.

Adding Events

Yes, why not? If they wouldn't want us to edit it, they'd have set permissions to employee instead of user and employee.

Yeah a lot of the edits up there have been done by non-firaxis peeps. Mostly Frankenstein but I've added some stuff on there and no-one's taken issue with it yet. :D t'is what wikis are all about after all.
 
something like this

Code:
local barcaplayerid = 63;
local barcacheck = 0;
local MECH = 23;

local ALPSCOORDS = {
	somespot = { x = 1, y = 1 },
	thisspot = { x = 2, y = 2 },
	thatspot = { x = 3, y = 3 },
};

function HANNIBAL ()

	if ( barcacheck == 1 ) then return; end

	if ( Game.GetGameTurn() == 30 ) then
		for k,v in pairs( ALPSCOORDS ) do
			Players[ barcaplayerid ] :InitUnit( MECH, ALPSCOORDS[k].x, ALPSCOORDS[k].y );
		end
		barcacheck = 1;
	else
		return;
	end
end
Events.SpecificCityInfoDirty.Add ( HANNIBAL );

it's not that complicated if you look that over. if this then do that ;)

like xml editing except you can do stuff depending on what the xml value is equal to

Thanks, but it will probably be at least a year before I personally dabble with such scripts. In the mean time I'll just copy from you geniuses and use your utility tools :)
 
On game events: I want an event that runs a code at the start of the game only, that is at the start of 1st turn after loading all game date. I tried:
SerialEventStartGame
but it seems that this event is run pre-game when you press start game button, and game data like Players are not loaded before this event.

And I dont want to use something like this:
Code:
function My_Function()
    if (Game.GetGameTurn()==1) then
         .
         .
         My Code here
         .
         .
    end

end
Events.ActivePlayerTurnStart.Add( My_Function )
 
What kind of code do you need to run? You can just add code to the script itself and that is executed only once, when the script is run. If you define it as an InGameUIAddin, that should work fine.
 
the code calculates some global variables (at game start) that will be passed later to another lua script that will be run every turn.

Then just put it into the root of the script file. You can access all game data like Players from there.

For example
Code:
local i = 0
i = Players[Game.GetActivePlayer()]:GetID()
print(i)
 
I mean I want global variables used by separate lua files. if declared at the script root (loaded at InGameUIAddin) of one lua file, then the variables will not be passed to other lua files.

I know there is a share_data utility released in the forums, but I want to pass simple variables which shouldn't be vary complicated.
 
That will only work with static values, or where the variables are never used by another ui lua file, since all Lua states will have their own independent versions of the globals in the include, so if the value changes in one it won't be reflected in the other. you should use share_data, seriously.
 
Yeah a lot of the edits up there have been done by non-firaxis peeps. Mostly Frankenstein but I've added some stuff on there and no-one's taken issue with it yet. :D t'is what wikis are all about after all.

W.I.K.I.S.

Wantonly Implied Known Information, Sorta. :D
 
I mean I want global variables used by separate lua files. if declared at the script root (loaded at InGameUIAddin) of one lua file, then the variables will not be passed to other lua files.

I know there is a share_data utility released in the forums, but I want to pass simple variables which shouldn't be vary complicated.

ShareData isn't very complicated at all. There are user friendly functions integrated into SaveUtils, primarily: share().

Code:
Include( "SaveUtils" ); MY_MOD_NAME = "MyMod";

local myVariable = nil;
local myDefault = {};

function shareData()
  myVariable = share( "myVariable",  myVariable or myDefault );
end
Events.LoadScreenClose.Add( shareData );

Every file you put that in will share the same variable upon load screen close. Notice I'm assuming myVariable is a reference. ShareData allows for primitives, but it makes more sense to put your primitives in a shared table instead and then grab them by key, ie: myVariable["primitive"].
 
The alternative is to pass the variable manually. This can be performed with a LuaEvent, however, lua events are executed on a separate thread, so you can't get a return but rather provide a reference to a table to obtain the data.

Code:
local tbl = {};
LuaEvents.GetMyVariable( tbl );
local myVariable = tbl[1];

Code:
local myVariable = 0;

function onGetMyVariable( tbl )
  table.insert( tbl, myVariable );
end
LuaEvents.GetMyVariable.Add( onGetMyVariable );
 
It's a very good question. I assume you can attach a function to the Events object, but how would the underlying code know when to execute it?
 
It's a very good question. I assume you can attach a function to the Events object, but how would the underlying code know when to execute it?
source code more than likely, unless there's some yet to be known method to define event triggers in lua, which would be really cool, but that's a pipe dream ;)
 
*puff*... *puff*... Lets keep the dream alive! :D
 
Back
Top Bottom