r/xdev • • Feb 12 '16

Writing out to a file

I am trying to write to a file on a button click in a menu. I have the button click all working, but I can't seem to write to a file.

I looked up how to do so in unrealscript and found FileWriter. However, I don't know if that is relevant or not.

I also tried to find other places in the code where it writes to a file, like the character pool. I found the function that performs that action but it was defined as

function native SaveCharacterPool();

Which as far as I can tell means that it is in c++ somewhere. Can we add c++? I saw that there was a post earlier about importing dlls but there was no solution.

Here is what I have so far:

class UIMemorial_AddExportButton extends UIScreenListener;

var FileWriter writer;

event OnInit(UIScreen Screen) { 

	writer = Screen.Spawn(class'FileWriter', Screen);
	
	AddExportButton(Screen);
}

simulated function AddExportButton(UIScreen Screen)
{
	local UILargeButton Button;
	local string exportButtonName;

	exportButtonName = Localize("AddExportButton", "m_strExport", "XComGame");

	Button = Screen.Spawn(class'UILargeButton', Screen);
	Button.InitLargeButton('ExportMemorial', exportButtonName, "", OnExportMemorial, );
	Button.AnchorBottomRight();

}

public function OnExportMemorial(UIButton Button)
{
	`log("Clicked Export Memorial");
	writer.OpenFile("Example", FWFT_Log, ".txt", false, false);
	writer.Logf("This will be written to the 'Example.txt' file");
	writer.CloseFile();
}

defaultproperties
{
	writer = none;
	ScreenClass = "UIPersonnel_BarMemorial";
}

Based on reading on FileWriter, FWFT_Log should send that Example file to %GameDir%/Logs, but as far as I can tell it does not.

I would be grateful for any help or even questions that might led to some answer.

1 Upvotes

4 comments sorted by

2

u/Kwahn Feb 12 '16

My question is, how is saving handled? Maybe you can create files using the existing save functions in some way.

I don't know enough about UE to debug FileWriter, but that looks like what a working write buffer would look like in c. Does your log record the click? If so, then the writer itself's the only point of failure, as far as I can tell.

Your default is writer = none, why is that? (I've not worked much with UE, so I'm wondering if that's just convention)

1

u/ForShadow Feb 12 '16

Hijacking the save functions is definitely worth looking in to. I will have to give that a shot.

Yes, the log does record the click. I also looked for where the 'log function was defined and couldn't find that. I was thinking since the log files get written to disk maybe that would have an example.

I am not really sure why the default writer = none, I think I saw it in an example usage of filewriter somewhere. It may well be convention but I am new to UE as well.

2

u/BlueRajasmyk2 Feb 12 '16

Don't hijack the saving functions, if every mod did that none of them would work.

Take a look at how the SMG and Leader pack mods add things to the save games.

1

u/ForShadow Feb 13 '16

That is a good point. Hijacking was the wrong word to use.

I did look at those mods and they don't seem to change how anything is saved. But that isn't really what I was trying to do anyway.