Access a singleton variable using a local variable?

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

Basically, i have a singleton to keep track of the stock of a number of items, it looks like this:

var item0 = 6
var item1 = 3
var item2 = 8

you get the idea.

What i want is to be able to access those variables, using a variable in another node. For example:

var take_item = item2

Stock.take_item -= 1

This, of course, doesnt work because “take_item” is not a variable on the “Stock” singleton, so how can i “translate” between the two?

Thanks in advance!

:bust_in_silhouette: Reply From: Tato64

Found the solution:


works perfectly!