I found some sort of a list online and got it to work as intended The command "addtoaliste" is adding a parameter to the list "aliste". It's defined by newcommands, so I have problems getting it to work within environments such as enumerate, as any changes are only done locally.
I'll try to change my implemented list to be working with global definitions (gdef). But first my "command-code":
\documentclass{scrartcl}
\usepackage{ifthen}
\newcommand{\aliste}[1]{\empty}
\def\zaliste#1\relax{\def\aliste##1{#1}}
\newcommand{\addtoaliste}[1]{%
\ifthenelse{\equal{\aliste{}}{}}{
\expandafter\zaliste\aliste{##1}#1\relax}
{\expandafter\zaliste\aliste{##1},#1\relax}
}
\begin{document}
Value: \aliste{}\\ %Returns empty list
\addtoaliste{1}
Value: \aliste{} %Returns 1
\begin{enumerate}
\item First Point.
\addtoaliste{2}
\end{enumerate}
Value: \aliste{} %shall return 1,2, but still returns 1
\end{document}
I tried some changes and got to the following, but it still didn't work as intended:
\documentclass{scrartcl}
\usepackage{ifthen}
\gdef\aliste#1{}
\gdef\zaliste#1{\relax{\gdef\aliste##1{#1}}}
\gdef\addtoaliste#1{%
\ifthenelse{\equal{\aliste{}}{}}{
\expandafter\zaliste\aliste{##1}#1\relax}
{\expandafter\zaliste\aliste{##1},#1\relax}
}
\begin{document}
Value: \aliste{}\\ %Returns empty list
\addtoaliste{1}
Value: \aliste{}\\ %Returns 1
\begin{enumerate}
\item First Point.
\addtoaliste{2}
\end{enumerate}
Value: \aliste{}
\end{document}



\defby a\gdef:\def\zaliste#1\relax{\gdef\aliste##1{#1}}. – Sep 23 '19 at 22:37\gdefs but with the fact that the first code has\newcommand{\aliste}[1]{\empty}, which is not the same as\def\aliste#1{}, and thus the "globalization" to `\gdef\aliste#1{}" does not work. – Sep 23 '19 at 22:52