Page 1 of 1

[0.17.x] slider_value and on_gui_value_changed

Posted: Wed Apr 24, 2019 3:56 pm
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?

Re: [0.17.x] slider_value and on_gui_value_changed

Posted: Wed Apr 24, 2019 4:52 pm
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.

Re: [0.17.x] slider_value and on_gui_value_changed

Posted: Wed Apr 24, 2019 7:03 pm
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.

Re: [0.17.x] slider_value and on_gui_value_changed

Posted: Thu Apr 25, 2019 3:12 pm
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.

Re: [0.17.x] slider_value and on_gui_value_changed

Posted: Thu Apr 25, 2019 7:45 pm
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)?

Re: [0.17.x] slider_value and on_gui_value_changed

Posted: Thu Apr 25, 2019 7:59 pm
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.