game.write_to_clipboard

Place to ask discuss and request the modding support of Factorio. Don't request mods here.
Post Reply
User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 333
Joined: Tue Jul 08, 2014 10:06 am
Contact:

game.write_to_clipboard

Post by LuziferSenpai »

Hey,

it would be cool if we could get a the function in the Title to copy a String into the Clipboard of the User.

Greetz,

Luzifer
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai

User avatar
mat1k
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Sat Dec 22, 2018 8:48 am
Contact:

Re: game.write_to_clipboard

Post by mat1k »

That would be dangerous in the hands of sloppy modders.

Put in on_tick and have it dump a large amount of data to clipboard and the game would hopefully crash before the computer.

User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 333
Joined: Tue Jul 08, 2014 10:06 am
Contact:

Re: game.write_to_clipboard

Post by LuziferSenpai »

mat1k wrote:
Sun Sep 15, 2019 6:15 pm
That would be dangerous in the hands of sloppy modders.

Put in on_tick and have it dump a large amount of data to clipboard and the game would hopefully crash before the computer.
Yea, but that can happen with MANY thing, there is game.write_file too ;)
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai

User avatar
mat1k
Long Handed Inserter
Long Handed Inserter
Posts: 55
Joined: Sat Dec 22, 2018 8:48 am
Contact:

Re: game.write_to_clipboard

Post by mat1k »

LuziferSenpai wrote:
Sun Sep 15, 2019 6:54 pm
mat1k wrote:
Sun Sep 15, 2019 6:15 pm
That would be dangerous in the hands of sloppy modders.

Put in on_tick and have it dump a large amount of data to clipboard and the game would hopefully crash before the computer.
Yea, but that can happen with MANY thing, there is game.write_file too ;)
That however can't deny the players the ability to use copy/paste while the game is running. If on tick was used with write_to_clipboard then as long as the game was running you would be unable to use your clipboard. As anything you try copy will immediately be replaced by the game.

User avatar
LuziferSenpai
Filter Inserter
Filter Inserter
Posts: 333
Joined: Tue Jul 08, 2014 10:06 am
Contact:

Re: game.write_to_clipboard

Post by LuziferSenpai »

Yea, still its useful
Coding is awesome!
Animes are love!
Factorio is life!

My MODs:
Click

Greetz,

Senpai

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: game.write_to_clipboard

Post by PyroFire »

What about a command that itself runs lua? (like /c but puts the "return" value on clipboard)

Code: Select all

/clipboard __modname__ return serpent.line(global.my_table)
for example.
This way a player must explicitly tell the game to do it, and can't be done randomly via script.

adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

Re: game.write_to_clipboard

Post by adamius »

game.write_to_clipboard has a bunch of issues. Not sure if the benefits outweigh the annoyances.

Better off just having another kind of GUIelement you can add where you can specify what you want copied to the clipboard. If the user clicks that button, it shows a factorio supplied window of its own showing the text and a copy button to actually copy to the clipboard. Kind of like the existing Blueprint export window. It would show a text window previous and a Copy button as well as a Cancel button.

ClipboardElement(luaGUIelement ?)
text_to_clipboard : what the mod wants to send to the clipboard

This way:-
the mod can copy whatever into that element. It would look much like the existing blueprint export window.
the player *chooses* to click it. or they can ignore it.
the player can cancel if they don't like what they see.
no "per tick" nonsense.
no "overwriting clipboard" nuisance mods.

Why I'd want this:
standardise export of data via clipboard. common GUI element.
exfil settings from mods for whatever reason.
other blueprint-like settings can easily be exported without using write_file
notepad type mods can export and import todo lists for factory management.

PyroFire
Filter Inserter
Filter Inserter
Posts: 356
Joined: Tue Mar 08, 2016 8:18 am
Contact:

Re: game.write_to_clipboard

Post by PyroFire »

adamius wrote:
Wed Dec 18, 2019 12:49 am
standardise export of data
Though i like the convenience of putting stuff on clipboard, functionality to do this already exists.
We do not need to re-invent the wheel.

Use log(), e.g. log(serpent.block(global)) then get it from your log file.
game.write_file is good too.

There's your standardized export of data.
mat1k wrote:
Sun Sep 15, 2019 6:15 pm
That would be dangerous in the hands of sloppy modders.
Yeah and i can crash your factorio by doing while(true) log("hi") end.
But we do not describe while() loops as "dangerous".

adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

Re: game.write_to_clipboard

Post by adamius »

Files just aren't the same as the clipboard. Its as simple as that. Especially when you're exporting/importing blueprint-like structures. These are GUI operations. Much easier to explain to a room of kids how to export a blueprint etc than dig through the filesystem if that was the only way. I know this because Ive needed to do it.

Take my trainstops csv mod. It lets you import/export every trainstop and edit it outside factorio in something like libreoffice as a spreadsheet table. I can do that because I can show the text box and have copy and paste. Yes I have a csv export. But its clumsy. How do I then import the data back in using same mechanism? I can't. Using the clipboard makes the whole GUI based operation smooth, safe and useful. No digging through file structures under AppData etc.

I fully understand why game.read_file isnt an option the devs would be excited about. I don't want factorio based malware. I'm sure there are possibilities for mitigating these kinds of threats. Go for it. Limit the folder structure etc. I'm not necessarily against it. I can definitely see the downside of enabling it however.

For my purposes its basically a need for a button that copies mod supplied text to the clipboard in an easy way that people can easily follow.

User avatar
Therenas
Factorio Staff
Factorio Staff
Posts: 232
Joined: Tue Dec 11, 2018 2:10 pm
Contact:

Re: game.write_to_clipboard

Post by Therenas »

adamius wrote:
Wed Dec 18, 2019 11:07 am
Take my trainstops csv mod. It lets you import/export every trainstop and edit it outside factorio in something like libreoffice as a spreadsheet table. I can do that because I can show the text box and have copy and paste. Yes I have a csv export. But its clumsy. How do I then import the data back in using same mechanism? I can't. Using the clipboard makes the whole GUI based operation smooth, safe and useful. No digging through file structures under AppData etc.

I fully understand why game.read_file isnt an option the devs would be excited about. I don't want factorio based malware. I'm sure there are possibilities for mitigating these kinds of threats. Go for it. Limit the folder structure etc. I'm not necessarily against it. I can definitely see the downside of enabling it however.
Importing things from a file or a players clipboard isn't doable because it would break determinism in multiplayer. There are other reasons as well, but that is the main one.

adamius
Long Handed Inserter
Long Handed Inserter
Posts: 73
Joined: Mon Mar 19, 2018 9:18 am
Contact:

Re: game.write_to_clipboard

Post by adamius »

Importing things from a file or a players clipboard isn't doable because it would break determinism in multiplayer. There are other reasons as well, but that is the main one.
Correct. The devs have already said this. File access in general systems can be made deterministic but its a world of pain guaranteeing it. Not worth the desync reports. Pragmatically the pain involved wont make the game substantially more fun either.

Don't conflate clipboard access with file access.Clipboard access is far more straightforward.

Post Reply

Return to “Modding interface requests”