How to make a visual script that activates something if a slider has changed?

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

I created a slider and now I want the slider can control the angle of a 2D polygon.

In reviews people say Godot is beginner friendly but it doesn’t seem so because the most simple things like trigger an event with a slider change doesn’t work.

And all I do in visual script doesn’t work and there aren’t any information to find how to get a change impulse which can trigger something.

:bust_in_silhouette: Reply From: njamster

I have no idea of how to do it in VisualScript (and honestly wouldn’t recommend anyone to work with VisualScript anyhow), but in GDScript it’s very easy.

Let’s say your scene-tree looks like this:

- Main (Node-Type: Node2D)
    - Polygon (Node-Type: Polygon2D)
    - Slider (Node-Type: HSlider)

Then you would connect the Slider’s value_changed-signal to a callback named _on_Slider_value_changed, let’s say that’s a function in the Main-script:

extends Node2D    

func _on_HSlider_value_changed(value):
	get_node("Polygon").global_rotation = value

I still don’t get it. Nothing works. Can you create a quick project file to demonstrate how a hslider change refresh the angle of an object?

Cubium | 2020-06-25 23:23

Sorry for the late reply, had some busy weeks! If you’re still struggling with this, take a look at the example project I uploaded here: Upload Files | Free File Upload and Transfer Up To 10 GB (That link will stop working after 30 days) If you haven’t yet, I’d recommend you work through this part of the documentation - it will teach you a lot of fundamentals.

njamster | 2020-07-15 12:08