Take your dim statement out of the for loop and define it as a float (which is what it would default to with the # at the end) since you are getting the sprite position and that is a float value.
dim origionalx#[2] as float
for i = 1 to 2
origionalx#[i] = getspritex (sprites[i])
next i
And you don't show how the sprites array is defined and filled (is it dimmed as 2 and an integer?).
Array declarations should not be in loops of any sort, since that sort of redeclares it and might mess with the values.
You are mixing using the index 'i' and hard index values and it isn't clear if that is what you intend.
In the first 'if', you use the 'i' index in all cases. In the second 'if', you use the 'i' index to check the sprite against its original position but then use '2' as the index to store the current position of the sprite indexed with 'i'. Shouldn't the '2' be 'i' or the 'i' be '2'?
In the fourth if, you use '1' as the index in the logic and then 'i' as the index in the action. Shouldn't the '1' be 'i' or the 'i' be '1'?
It looks like you would get a very strange set of interactions with what you have.
And you need to set your logic up so that it doesn't set the direction variable one way and then sets it the other way almost immediately.
Keep in mind that you won't see the affects of any sprite changes until the next Sync(). You might only see the last thing done and there won't be any changes between operations on the sprite until the Sync(). So, setting a sprite in one location in one line and then checking to see if it is in that position a couple of lines later won't catch the new position because there was no Sync() call to cause the setting to 'take'.
Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master