How to move a ScrollBar in GDScript? [Godot 3.0]

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Rammschnev

So docs for ScrollBar and ScrollContainer are very scant. It appears that, like a few other controls, the scroll bar is set up to work exclusively with mouse input, but I’m making a game that uses joypads only. Changing ScrollContainer.scroll_vertical directly does not work, nor does calling ScrollContainer.set_v_scroll(x).

Essentially, I have recreated the ItemList node from scratch to work with joypad input, and what I need is to mirror the functionality of ItemList.ensure_current_is_visible(). To even start to do that, I need to be able to move the scroll bar from code. It would be a real chore to have to recreate the entire functionality of ScrollContainer as well =/ Can anyone help?

:bust_in_silhouette: Reply From: Andrea

I dont understand, do you want the joypad to act like a mouse (dragging the scroll), or do you want it to simply move the list up and down while pressing up and down?

If the latter, why do .scroll_vertical doesnt work? I dont have a joypad so i cannot check exactly, but it works with the keyboard: simply link the input(event) to the .scroll_vertical

func _input(event):
 if event.is_action_pressed("ui_up"):
   $Scroll.scroll_vertical+=1

Sorry for the delay! @Thebluefish on the Godot Discord helped me solve this. It turns out that a manual call to $Scroll.update() was needed after updating scroll_vertical, and then everything worked fine.

Rammschnev | 2018-09-22 17:12

:bust_in_silhouette: Reply From: Rammschnev

Thanks to @Thebluefish on the Godot Discord for helping me figure this out. All that is needed is a manual call to $ScrollContainer.update() after changing the value of $ScrollContainer.scroll_vertical. As long as this doesn’t happen in the _ready function, it works as intended.