# Preplexing prob with Arrays and Functions

**URL:** <https://forum.kirupa.com/t/preplexing-prob-with-arrays-and-functions/108992>\
**Category:** Uncategorized\
**Created:** [April 30, 2004, 4:01pm UTC](https://forum.kirupa.com/t/preplexing-prob-with-arrays-and-functions/108992 "2004-04-30T16:01:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Danneman](https://avatars.discourse-cdn.com/v4/letter/d/b19c9b/32.png) [@Danneman](https://forum.kirupa.com/u/Danneman)\
**Post date:** [April 30, 2004, 4:01pm UTC](https://forum.kirupa.com/t/preplexing-prob-with-arrays-and-functions/108992/1 "2004-04-30T16:01:07Z")

</div>

Well, Ive been trying to pin down the problem with this code for several hours now, but no luck.

This is what I do:  
I convert a string with numbers to an array, and pass that array as a parameter to a function, which is supposed to use it in a switch-case statement. But that wont work.

```auto

// Create string with numbers
s_StringToArray = "0, 1, 3, 2";

// Convert String to Array	
arr_myArray = s_StringToArray.split(", ");

// Call function and submit array as parameter
fn_LoadContent(arr_myArray);	

// Function that recieves the array as a parameter, and uses it in a switch-statement
function fn_LoadContent(arr_myArray){
	
	// This debug will output the correct array
	trace ("arr_myArray = " + arr_myArray);
	
	// Select depending on what number is in arr_myArray[1]
	// ! This is where it goes wrong - the switch-case wont use the array submitted array.
	// ! If I on the other hand sends an array which has NOT been converted from a String, it WILL work.
	switch(arr_myArray[1]){
		case 1:	
			// do something
		break;
		case 2:
			// do something else
		break;
	}
}

```

If I on the other hand use a predefined array (not converted from sting) and send it along with the function, it WILL work.

```auto

// Define Array	
arr_myArray = [0, 1, 3, 2];

// Call function and submit array as parameter
fn_LoadContent(arr_myArray);	

// Function that recieves the array as a parameter, and uses it in a switch-statement
function fn_LoadContent(arr_myArray){
	
	// This debug will output the correct array
	trace ("arr_myArray = " + arr_myArray);
	
	// Select depending on what number is in arr_myArray[1]
	// ! This works
	switch(arr_myArray[1]){
		case 1:	
			// do something
		break;
		case 2:
			// do something else
		break;
	}
}

```

And to add to the confusion, in the first example the debug-code (trace) will output the correct array, meaning it HAS been passed along as a parameter.

This is driving me insane :crazy:
