The scope of a variable is where you declared it.
time, are declared in
slide_ice_shelf, and accesible in there.
end is declared inside the
if (and another in
if ends, the variable is lost (same for
What you have to do is to declare the variable where you want to be accesible, the class, a function, or inside a while/if/for to use mostly as auxiliar variable inside them.
In your case, do a
var end on the function scope (outside and before the if) and assign values inside it.
var speed = 800
var start = iceShelfSprite.get_pos()
if placement == "up":
end = Vector2(150,0)
end = Vector2(150,500)
var distance = start.distance_to(end)
var time = distance / speed
if has many conditions, you may need to set a initial value to the variable (not this case,
else does that) or check if it is null later.
Is a common practice to set all the vars (even uninitialized) at the start of the function/method/block where they will be accesible too, but that depends on your coding style.