If you are using a horizontal selection the above code willl work. Yet, the valueSum() function works much easier, if you place all scale items in a "scale" question. Note, that you can configure a fully labelled scale to display each item separately (very similar to a bunch of horizontal selections).