I have defined a custom environment (using the tocloft package, thanx to Juan) that looks like:
\newcommand{\listscriptname}{List of Scripts}
\newlistof[chapter]{script}{spt}{\listscriptname}
\def\thescript{\thechapter-\arabic{script}}
\newenvironment{script}[2][]
{ \vspace{3mm}\hspace{3mm}
\colorbox{orange}{\refstepcounter{script}
\textbf{Script~\thescript #1:code/#2.groovy}}
\addcontentsline{spt}{script}
{\protect\numberline{\thescript}#1~~code/#2.groovy}
}
{}
which I use like:
\begin{script}{FooBar}
\label{script:FooBar}
BitStream.
\end{script}
And refer to it with:
Script~\ref{script:FooBar}.
But instead of the script environment number, I get the number of the section.
What am I doing wrong (I did try several variations...)?