Hi Guys,
as per code from AppGameKit Official Tutorial Guide.pdf p388 - modified slightly for act 11.14, below:
// Project: Shuffle
// Created: 2015-02-17
//*** Program constants ***
#constant SIZE = 18
//***************************************
//*** Main program ***
//***************************************
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "Shuffle" )
SetWindowSize( 1024, 768, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1024, 768 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
//SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
SetDisplayAspect(1024/768.0)
//*** Clear the screen ***
ClearScreen()
//*** Declare main variables ***
list as integer[]
list2 as integer[]
contents as string
contents2 as string
//*** Set up array, convert to string ***
list = InitialiseArray()
contents = IntArrayToString(list)
//*** Set up array2, shuffle and convert to string ***
list2 = InitialiseArray()
ShuffleArray(list2)
contents2 = IntArrayToString(list2)
//*** Display contents of array and shuffled array2 ***
do
Print(contents)
sync()
sleep(1000)
Print(contents2)
sync()
sleep(1000)
loop
//***************************************
//*** Functions ***
//***************************************
//*** Returns array with values 1 to 20 ***
function InitialiseArray()
//*** Create array
result as integer[SIZE] //*** Set up values in array ***
for c = 1 to SIZE
result[c] = c
next c
endfunction result
//*** Shuffle contents of array ***
function ShuffleArray(list ref as integer[])
for c = 1 to SIZE * 20
//** Generate two DIFFERENT subscript values **
sub1 = Random(1,SIZE)
repeat
sub2 = Random(1,SIZE)
until sub1 <> sub2
//** Swap values at these positions **
list.swap(sub1,sub2)
next c
endfunction
//*** Return array as string ***
function IntArrayToString(list as integer[])
result as string = ""
for c = 1 to list.length
result = result + Str(list[c])+ " "
next c
endfunction result
result = result + Str(list[c])+ " "
contains a tab in the string and will eventually corrupt the string for no reason.
Change it to 4 spaces, all good.
Tried with chr codes:
Line feed, new line works as expected
code$ = chr(10)
result = result + Str(list[c])+ code$
horizontal tab has same effect as string tab
code$ = chr(9)
result = result + Str(list[c])+ code$