There are two problems here.
1. You have 2 variables called 'scalaRiduz'. They may look the same, but they are completely different. You could have written:
var scalaRiduz1111:Double = 0
…
func scalaTrafila (…)
{
var scalaRiduz2222:[Double] = [0, 1, 2]
…
}
Why? Because a 'var' statement always declares a new variable. In your existing code, the 'scalaRiduz' inside the function hides the 'scalaRiduz' outside the function. But they're still different variables.
2. This isn't your real code. In your "main program", your 'scalaRiduz' isn't even array — it has type "Double", not "[Double]".
Here's what I think happened. You had code like this, in a single file:
var scalaRiduz:[Double] = []
func scalaTrafila (…)
{
scalaRiduz:[Double] = [0, 1, 2] // <-- Note that there is NO "var"
}
print (scalaRiduz[0]) // prints "0"
Then you split it into 2 files:
var scalaRiduz:[Double] = [0]
scalaTrafila ()
print (scalaRiduz[0])
func scalaTrafila ()
{
scalaRiduz:[Double] = [0, 1, 2] // <-- Error: 'scalaRiduz' is not defined
}
and then "fixed" the function like this:
func scalaTrafila ()
{
var scalaRiduz:[Double] = [0, 1, 2]
}
Now your main code will give you the error "Index out of range". Right?