# "Missing number, treated as zero" when returning length from function

This MWE fails when I return a length and some string (I noticed it when I tried to debug some TikZ macros I wrote).

\documentclass{scrartcl}
\usepackage{etoolbox}

\newlength{\mylength}
\setlength{\mylength}{20mm}
\newcommand\getlength[1]{
\ifnumcomp{#1}{=}{1}{\mylength}{}
\ifnumcomp{#1}{=}{2}{\mylength + 10mm}{}
\ifnumcomp{#1}{=}{3}{\mylength}{}
}
\begin{document}
\getlength{1}
\getlength{2} % As soon as this line exists, ...
\getlength{3} % ...this line returns: "Missing number, treated as zero."
\end{document}


Why is that so and how can I make it work?

• I will accept an answer that also explains, where the problem comes from. Oct 18, 2018 at 13:06
• \mylength expects a following number to assign the register. it doesn't output the current value. The first two commands do basically \mylength=\mylength and then print the + 10mm. And the last \mylength is missing its number. Oct 18, 2018 at 13:12
• So \mylength5cm would be equivalent to \setlength{\mylength}{5cm}? If you want the credit, I would take your comment as an answer. Oct 18, 2018 at 13:35

\mylength expects a following number to assign the register. It doesn't output the current value.
So the first two commands do basically \mylength=\mylength and then print the + 10mm. And the last \mylength is missing its number.
I found out that I can prevent the error by returning \the\mylength instead, but I don't know yet why the problem arises.