I am trying to set a global variable via function call based on the specified options/values of the function call. Here's my code:
let g_Pl = [];
function prepare() {
let s = 0;
s = 1;
g_Pl[s] = 5;
s = 2;
g_Pl[s] = 8;
s = 3;
g_Pl[s] = 10;
}
function getInfo(s,map,pl) {
switch (map) {
case "test":
pl = g_Pl[s];
break;
}
}
function test() {
let local_Pl;
getInfo(1, "test", local_Pl)
console.log(local_Pl);
}
prepare();
test();
But the console output is "undefined" and I am wondering why? local_Pl is supposed to be set a value from getInfo which has to be "5" based on the parameters in prepare():
s = 1;
g_Pl[s] = 5;
Why it doesn't work ?