1)
well first off restart maya ^^
you have most likely defined $object before so you can not redifine it.
Maya remembers all variables you define each session. And the only way to clear it is to reboot maya. (as far as i know)
2)
secondly the "ls" command returns a string array.
so if you want to define it correctly you would need to write
string $object[] = 'ls -sl';
3)
now if you would want to use it in your window code you would need to tell maya which object in the string array you would want to use.
In order to do that write a number in the brackets like this.
$object[0]
(0 is the first object in the array)
so your window code will look like this.
window -title "sliderTest";columnLayout;
attrFieldSliderGrp -label "Translate X"
-min -10.0
-max 10.0
-fieldMinValue -100.0
-fieldMaxValue 100.0
-at ($object[0]+".tx");
showWindow;
( you need to use brackets and the + in order to make a correct syntax, read up on the mell syntax it will help you a lot.)
4)
here is a little bit extra for you to play with. Select several objects in your scene and run the following code.
// get your objects selection
string $myObjects[] = ls -sl;
//build window and layout
window -title "sliderTest";
columnLayout;
// for each object that is in the $myObjects array do the following code.
for ($thisObject in $myObjects){
attrFieldSliderGrp -label ($thisObject + " Translate X")
-min -10.0
-max 10.0
-fieldMinValue -100.0
-fieldMaxValue 100.0
-at ($thisObject+".tx");
}
showWindow;
have fun coding in mel ^^
edit: replaced # with // (python coding :P)