Problems with setting global variable to slider

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

Hello, I am working on a car game where I want to have a sort of debug/developer mode where you can use sliders in game to control the cars speed, acceleration ect… I have a problem when i do
extends HSlider

var car = get_node("res://Assets/Cars/VW/vw.gd").MAX_ENGINE_FORCE
func _on_Slider_value_changed():
	car = HSlider.value

I get

Invalid get index ‘MAX_ENGINE_FORCE’ (on base: ‘null instance’).

I have a simpleton set up

But it gives me that error. What should i do?

:bust_in_silhouette: Reply From: jgodfrey

Assuming the autoload script shown above (vw.gd) really does contain a MAX_ENGINE_FORCE variable, you should be able to reference it in other script simply by using:

vw.MAX_ENGINE_FORCE

So, untested, but something like this should work:

func _on_Slider_value_changed():
    vw.MAX_ENGINE_SLIDER = HSlider.value