[0.17.x] slider_value and on_gui_value_changed

Things that we aren't going to implement
Post Reply
osldgoth
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu Feb 26, 2015 3:52 am
Contact:

[0.17.x] slider_value and on_gui_value_changed

Post by osldgoth »

Currently if lua code changes the slider value the event "on_gui_value_changed" is NOT called.

Code: Select all

event.element.slider_value = x
the event is only called when the player clicks on a slider to change the value.

The definition of "on_gui_value_changed" as per wiki is
Called when LuaGuiElement slider value is changed (related to the slider element)
I expect it to actually be called when the slider value is changed regardless of the change being the player or code.

Can we(mod authors) have this change or should the wiki state that the event is called only when the player changes the slider value?

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: [0.17.x] slider_value and on_gui_value_changed

Post by eduran »

As far as I can see, events are rarely (ever?) triggered by changes made through lua code. But you can use script.raise_event to manually raise the event when your code changes the slider value.

Rseding91
Factorio Staff
Factorio Staff
Posts: 13209
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.17.x] slider_value and on_gui_value_changed

Post by Rseding91 »

eduran wrote:
Wed Apr 24, 2019 4:52 pm
As far as I can see, events are rarely (ever?) triggered by changes made through lua code. But you can use script.raise_event to manually raise the event when your code changes the slider value.
Correct. Game events almost never fire when a mod changes something - by design.
If you want to get ahold of me I'm almost always on Discord.

osldgoth
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu Feb 26, 2015 3:52 am
Contact:

Re: [0.17.x] slider_value and on_gui_value_changed

Post by osldgoth »

Or, here's an idea, one could try using 'script.raise_event'. Only an idiot would not think to use that. It's clear as day

I got it working thanks.

osldgoth
Long Handed Inserter
Long Handed Inserter
Posts: 93
Joined: Thu Feb 26, 2015 3:52 am
Contact:

Re: [0.17.x] slider_value and on_gui_value_changed

Post by osldgoth »

hmm, turns out that I didn't really even need to use script.raise_event, could just call the function myself. Is there any reason to skip script.raise_event? does it make everything slower (or are we talking about a few ticks)?

eduran
Filter Inserter
Filter Inserter
Posts: 344
Joined: Fri May 09, 2014 2:52 pm
Contact:

Re: [0.17.x] slider_value and on_gui_value_changed

Post by eduran »

If you are doing something that other mods might want to react to (e.g. destroying entities), you should use script.raise_event. If your slider is used for your own mod only (which is usually the case with GUI elements), there is no reason to fire an event.

Post Reply

Return to “Won't implement”