baxslash, I implmented your inserts and removes in my own functions and I found that for some reason they were introducing duplicates, to overcome this I came up with the following:
//******************************
//Project: Array_Rotation
//Created: 2015-02-26
//Coded By Dead Pixel.
//******************************
//Set window properties.
SetWindowTitle( "Array_Rotation" )
SetWindowSize( 1024, 768, 0 )
//Set display properties.
SetVirtualResolution( 1024, 768 )
SetOrientationAllowed( 1, 1, 1, 1 )
global test_items as String[10] = [" 1 ", " 2 ", " 3 ", " 4 ", " 5 ", " 6 ", " 7 ", " 8 ", " 9 ", " 0 "]
do
//Right arrow key
if(GetRawKeyPressed(39)) = 1 then shift_array_elements_right()
//Left arrow key
if(GetRawKeyPressed(37)) = 1 then shift_array_elements_left()
for x = 0 to (test_items.length - 1)
PrintC(test_items[x])
next x
Sync()
loop
function shift_array_elements_right()
test_items.insert(test_items[test_items.length-1], 0)
test_items.remove(test_items.length)
endfunction
function shift_array_elements_left()
test_items.insert(test_items[0], test_items.length)
test_items.remove(0)
endfunction
I've tested this and it seems to be working OK.
As it is a single call to either function only rotates the elements by one place, modifying the function to accept an integer parameter for use in a for.....next loop would allow us to specify how far right or left to shift the elements. In addition to this if we pass in a boolean value to indicate which direction to rotate in then we can have a single function instead of two where we use the boolean value in an if....else statement to determine the direction - false = shift left, true = shift right.
RotateArrayElements(array ref as string[], boolean direction, int amount_to_shift_by)
But perhaps speed of execution would be an issue if we introduce the loop and the if,else functionality?
//******************************
// Coding In BASIC using AppGameKit V2
//******************************