Community Forum

methods for input and save/load

Forum Overview >> Scripting

CategoryScripting
Created08.07.2015 01:41


Bilbo Beutlin (BBeutlin) 08.07.2015 01:42
1) After a certain function I need to flush the input buffer to avoid unwanted following actions.
In a mod I found "Input.keyPressedState = {}" - but this doesn't work properly.
What is a safe way to clear the input buffer?

2) For savegame I want to add a few additional attributes in the "careerSavegame.xml". What should be used?
Are there functions equivalent to the vehicles' "getSaveAttributesAndNodes" and "loadFromAttributesAndNodes"?

3) According to 2) I'm searching for a method for a quickSave function/hotkey (immediate save, without menu and confirmation).
What is recommanded to use?

Emil Drefers (Unknown) 08.07.2015 08:22
Hi,

can you explain 1) more exactly?
For me it sounds like you maybe should try to find a input binding / key for your function.

2) Nope, there is no easy way to hhok into the saving of this file.
But you could create (and save to) your very own .xml file, which would be specifically for your mod.

3) Determine/find the current savegame slot and flush your data to your own file ;)

Cheers,
Emil

Bilbo Beutlin (BBeutlin) 08.07.2015 11:44
The 1) is for my hotkey tool. It uses the NumPad keys together with left and right Ctrl and has its own keyEvent evaluation. I didn't want to use input bindings - it spams the inputBinding.xml and makes evaluation much more extensive.
The problem is a bug in FS which executes single key assignments even if the key is pressed together with a qualifier. So I need to flush/clear the input buffer after my hotkey function, else possible single key assignments on the NumPad get executed.

2) Ok - the datas I could save in my own file. I've seen a method kind of
CareerScreen.saveSavegame = Utils.appendedFunction(CareerScreen.saveSavegame, myMod.saveSettings);
Could I use this?

3) However I'd like to have a quickSave function/hotkey full functional with the normal save, but without having to struggle with menu and confirm requester. Just the last one is totally useless and stupid: there's only one slot to save and no reasonable background for this requester. It's more like the Windows' joke requester: "your mouse has moved - please confirm". ;-)

Emil Drefers (Unknown) 09.07.2015 15:07
Hi,

1) everything you could do is kind of a dirty hack. I guess it's better to wait for a fixed version of FS.
FS17 will have an improved input handling.

2) Jep, append your function to the "saveSavgame" should work

3) A "confirm requester" makes sense otherwise you could destroy data you wanted to keep.
Anyway, just call your function to save the data should do the trick, right (as long as you know which savegame to save to?



Bilbo Beutlin (BBeutlin) 09.07.2015 15:29
Hi Emil, thanks again

hmm .. no regular function to flush input buffer? That's disappointing. ;-)
Then please tell me, what 'dirty hack' I could use temporary. It's only for my personal usage, I don't intend to publish my mod soon. And hopefully a new patch solves the problem finally.

Nonetheless I don't see a sense in the confirm requester. In general the user has clicked 'SAVE' before in full intention, the game can be saved to one slot only (without choice) and a backup of old save is made automatically.

Emil Drefers (Unknown) 10.07.2015 08:10
Hi,

about saving ...
Imagine your on a console (no access to backup), just accidentally hit the wrong button and did something wrong before (drive a vehicle into the sea, destroyed some crops, ...) - it's just common sense ; )

About flushing the input ...
Well, it's a public forum, lots of people might gather the information.
Anyhow, just an untested hint:
The class InputBinding has a table called actions. These values are 'divided' into analog and digital ...
Just have a close look at it and I guess you'll find a way.

Cheers,
Emil

Bilbo Beutlin (BBeutlin) 10.07.2015 13:06
Ok, for console users the requester might be useful. But for desktop I'd wish it could be deactivated, eg. by tag in game.xml <confirmSave>false.

I tried it with direct function call CareerScreen.saveSavegame() , but obviously it needs argument/s, at least 'savegame'. How do I get the right arguments? I found in the global tables 'Savegame' - but since I'm unsure about meaning, I didn't try yet.
Usually I'm not anxious to experiment, but if could mess up datas on drive, I'm a little more careful. ;-)

To the flush problem: I found 'io.flush()' - usually also device input is handled as IO stream, perhaps I can call this function? It was a more 'serious' and engine compatible method, but what arguments are needed and how to get them?

Emil Drefers (Unknown) 10.07.2015 16:51
Hi,

you only need to pass the current savegame (information) when calling "CareerScreen.saveSavegame()", which is the following table:
g_currentMission.missionInfo

"io.flush()" will very likely not work, if it can be called at all.

Cheers,
Emil

Bilbo Beutlin (BBeutlin) 14.07.2015 16:38
InputBinding.actions: I've set all hasEvent, lastIsPressed to false, but didn't work.
So I guess the InputBinding evaluation is made already before my code gets executed.
Well, I had to eat the bitter pill and spam my InputBinding.xml with a bunch of dummy entries. Also not perfect: if any entries have no 'category' attribute, the single key is executed regardless.

The 'QuickSave' I got nearly to work with CareerScreen.saveSavegame(). The game is saved, but there's missing something. The "saving" notifier doesn't appear and I get
Error: Running LUA method 'onSaveComplete'.
... CareerScreen.lua(346) : attempt to index field 'savegames' (a nil value)
I guess that's for the backup handling. There must be an earlier entry point for saving.

Then I tried InGameMenu.saveCurrentGame(), but had no idea about parameters, got
Error: Running LUA method 'update'.
... InGameMenu.lua(565) : attempt to perform arithmetic on field 'savingDuration' (a nil value)

Emil Drefers (Unknown) 15.07.2015 08:17
Hi,

does your call really looks like:
CareerScreen:saveSavgame()
?

Well,... you would need to call the function of an instantiated object, namely g_careerScreen.

Sorry for eventually misleading you.

Cheers,
Emil



Bilbo Beutlin (BBeutlin) 16.07.2015 08:07
Now I'm a little confused. Do you mean using 'CareerScreen:saveSavegame(g_careerScreen)' instead 'CareerScreen:saveSavegame(g_currentMission.missionInfo)'?

Or really 'g_careerScreen:saveSavegame(g_currentMission.missionInfo)'?

Since only the table 'CareerScreen' has a function 'saveSavegame', where 'g_careerScreen' has not.

Emil Drefers (Unknown) 16.07.2015 08:40
Hi,

yes I meant:

g_careerScreen:saveSavegame(g_currentMission.missionInfo)

or

CareerScreen.saveSavegame(g_careerScreen, g_currentMission.missionInfo)


Cheers,
Emil

Bilbo Beutlin (BBeutlin) 19.07.2015 21:17
now my quicksave works perfectly :-)
Thanks for your hints, Emil


Note: Log in to post. Create a new account here.