obj= ['0000','1100','0110','0000'] //one of 6 possible objects: the 'z'
//defines what to replace with what when rotate
rot=[
'0030','1031','2032','3033',
'3123','3213','3303','2302',
'1301','0300','0210','0120',
'1121','2122','2212','1211']
//if rotate button was pressed
case "Rotate":
temp=obj.slice(0)
for( i=0; i<rot.length; i++ )
obj[rot[i][0]][rot[i][1]]=temp[rot[i][2]][rot[i][3]]
break;
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );
//Create a text label and add it to layout.
txt = app.CreateText( "Hello" );
txt.SetTextSize( 32 );
lay.AddChild( txt );
//Add layout to app.
app.AddLayout( lay );
alert (rotateMe(0,0,'1123'));
}
function rotateMe(pos,char,string) {
var ss='';
alert(string.length);
for (var i=0;i<string.length;i++) {
if (i==pos) ss+=char;
else ss+=string.charAt(i);
}
return ss
}
"Some of his coding is a bit tricksy, relying on stuff like implicit coercion of a string to an array
btn.SetText(("XO")[player]);
but he has cleaned up some of the worst excesses of that."
But I now suspect this was not intended to be tricksy at all but arises from a fundamental misunderstanding of what a JavaScript string is.
It really is important to get to grips with JavaScript basics. You might want to take a step back and look at some of the JavaScript references and tutorials on the net. Especially the beginners' stuff.
For instance, because JavaScript tries much too hard to be helpful and converts values to different data types all the time, you could spend months convinced that strings are arrays.
Strings are not arrays of any type. They cannot be changed, only replaced.
obj= newObject()
function newObject(){
return <objects array>[<random number>]
}
and I replaced the strings in the objects array with arrays (I made that only because strings are shorter to write), but the rotation failed anyways. As I said I'll working on that after finishing the other functions
Regards,
Alex
For example;
var arr = "1234567890".split("");
//test if it worked
if( Array.isArray(arr))
alert(JSON.stringify(arr));