Customizing the info that is shown on "ALT"

Place to get help with not working mods / modding interface.
Post Reply
User avatar
Wutklumpen
Burner Inserter
Burner Inserter
Posts: 12
Joined: Wed Sep 10, 2014 11:10 am
Contact:

Customizing the info that is shown on "ALT"

Post by Wutklumpen »

Hi,

i don't think you can help me here^^, but i give it a try anyways. I want to add my own behaviour for how my custom entity reacts to the "show info" view when pressed "alt-key".
I rolled through a metric f-ton of lue-files to find any evidence for the thing to be handled or condfigured by lua. Is this possible with the current modding api, or is it one of the hardcoded things, like it's bound to any container entities?

Even if not, can one at least read the setting whether the info-mode is on or off? Or are there keypress-Events, that are not documented in the wiki etc?^^ Then i could use them and print a text on the screen or something. (can one print text to the screen besides the console like thingy?^^)

Thanks in advance,
Wutklumpen
Fight back - if necessary strike first

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Customizing the info that is shown on "ALT"

Post by FreeER »

Wutklumpen wrote:Is this possible with the current modding api
no, it is hardcoded based on the entity.
Wutklumpen wrote:can one at least read the setting whether the info-mode is on or off? Or are there keypress-Events
Unfortunately, no.
Wutklumpen wrote:can one print text to the screen besides the console like thingy?^^
Finally! Something I can answer with a non 'no, sorry.' answer :) there's game.player.print (console), game.player.showmessagedialog (popup message/image and player presses 'tab' to continue), and you can use game.createentity to spawn flying-text entities like is done when picking up items (ie game.createentity{name="flying-text", position=game.player.position, text="Hello!"}). I suppose theoretically you could spawn a lot of entities that show up on the map in such a way as to spell/draw out a message there but...I've never tried :)

User avatar
Wutklumpen
Burner Inserter
Burner Inserter
Posts: 12
Joined: Wed Sep 10, 2014 11:10 am
Contact:

Re: Customizing the info that is shown on "ALT"

Post by Wutklumpen »

yay, thanks! This already helped me alot with some concerns. But, as always, now i have even more questions xD

The flying-text worked really well, but it seems to be a fire & forget system. God, i think i thought this would be more comfortable^^.

Code: Select all

game.createntity
does _not_ even return the created entity, so i have to scan the area for it. Then, when i found the specific object, i tryed to change the text-property, but flying-text.text seems to be private member.. this is so unsatisfying^^
I also wanted to change the duration of the flying-text, or it's animation to nil, so it stays where it is and emulates an static text.

I think i need to switch to a seperated frame.

Blabla, what am i trying to do? I browsed the ideas/suggestions and modrequest boards and read about a countdown for train stations (how long the train will stay there) and i thought: "yay, shouldn't be that hard"

First idea: take the vanilla trainstation, alterate the info view, done. NOPE
Second try: copy the vanilla train-station to a modded version, display the text as count down, done. NOPE. Well, at least not that easy^^
On Tick, each station has to scan for stopped trains, then get the trains timetable and the stoptime for this station, start a counter and update the flying-text's text with the remaining time.
So, since there seems to be no static text, and flying-text can't be changed, and overall it's extremly hard to find out what properties an object currently has, i think i need a third approach:

A gui-frame, that displays any stop of a train and the remaining time. This is not exactly what i imagined, but thats the only tool remaining.
And then i didn't even know if it's possible to read the train's timetable at all. Maybe i should check this first.

I think will take a look on DyTech, try what it's capable of and when i find a nice feature, i will dig down the code and look how it's done.

Anyways, thanks for your answer! =]
Wutklumpen
Fight back - if necessary strike first

User avatar
ludsoe
Fast Inserter
Fast Inserter
Posts: 243
Joined: Tue Feb 11, 2014 8:16 am
Contact:

Re: Customizing the info that is shown on "ALT"

Post by ludsoe »

Wutklumpen wrote:

Code: Select all

game.createntity
does _not_ even return the created entity, so i have to scan the area for it.
It does return entities it creates.

Direct copy paste from MoCombats Force-field Code.

Code: Select all

local Wall=game.createentity{name = "forcefieldwall", position= V}

User avatar
Wutklumpen
Burner Inserter
Burner Inserter
Posts: 12
Joined: Wed Sep 10, 2014 11:10 am
Contact:

Re: Customizing the info that is shown on "ALT"

Post by Wutklumpen »

o..k? Oo i will have to further investigate this, and if there is an exception for flying-text. I got "-1" in return while the entity was created perfectly fine. Thank you.
Fight back - if necessary strike first

User avatar
FreeER
Smart Inserter
Smart Inserter
Posts: 1266
Joined: Mon Feb 18, 2013 4:26 am
Contact:

Re: Customizing the info that is shown on "ALT"

Post by FreeER »

Wutklumpen wrote:i tryed to change the text-property, but flying-text.text seems to be private member.. this is so unsatisfying^^
I also wanted to change the duration of the flying-text, or it's animation to nil, so it stays where it is and emulates an static text.
yes it is private, though with the problems of moving and disappearing solved then all you really need to change the text is to destroy the old and create a new one with different text (not the most desirable method, but functional). Since flying-text is an entity you can find it's prototype within data\base\prototypes\entity, specifically in the demo-entities.lua file, and see that it has properties for speed and time_to_live. An 'obvious' assumption would be that setting speed to 0 would stop it from moving (it does) and that maybe time_to_live is decremented by one each tick (since it definitely doesn't last 150 seconds), so... maybe setting it to 0 or -1 will disable it (or at least cause Factorio to underflow it to the maximum of 4294967295 (ticks) or 19,884 hours!, instead and take a long time to reach 0 and die. you could also put the actual max...but 0 or -1 looks neater and more obvious that you're disabling the time, even if it's taking advantage of an underflow caused by Factorio decrementing the value before comparing it to 0 rather than Factorio actually realizing that it shouldn't kill it based on a sentinel value).

Since it is also, just another entity, you can create your own prototype of type "flying-text" with these values (and a different name) for your mod.

One last bit of info, you can change the color of the text during creation with "color = {r=float, g=float, b=float, a=float}" (the color type is mentioned on the wiki here) :) Oh, and as mentioned by ludsoe, game.createentity should return a lua/entity.
Wutklumpen wrote:And then i didn't even know if it's possible to read the train's timetable at all. Maybe i should check this first.
If by timetable you mean the train-station schedule that the player sets then yes (train.schedule I believe), however...I don't believe it's possible to get the name of a train station from the entity so...I'm not sure how you'd know where the train is within the schedule or the distance between the stations...I know there are a couple other train related mods already released so those authors probably know more about that aspect of the "api" than I do (I really haven't played with trains)

User avatar
Wutklumpen
Burner Inserter
Burner Inserter
Posts: 12
Joined: Wed Sep 10, 2014 11:10 am
Contact:

Re: Customizing the info that is shown on "ALT"

Post by Wutklumpen »

...i automatically skipped any *demo*.lua's and wondered, where the fork this entity is hidden xD.

And by using and trying and fiddeling with all kinds of reflection (and of course) reading basics of lua, i managed to find out that those only return "userdata", what looks like a pointer into the memory.
So... no reflection here^^

I'm going to find the flying-text entity now, copy it and then i will make it do what _I_ want! *insert evil laughter here*
Fight back - if necessary strike first

Post Reply

Return to “Modding help”