Suppose that I have a dimension (call it \shape) whose value is to change locally several times throughout a piece of code. Suppose also that I have defined a command (called \shifter in the code that follows) that effects these changes. Then, is it possible to use, at the beginning of the code, the final value that \shape will take on? For example:
\documentclass{article}
\usepackage{showframe}
\usepackage{etoolbox}
\setlength{\parindent}{0pt} % Cancel automatic indentation
\newdimen\shape % Let there be the dimension \shape
\setlength{\shape}{0pt} % Let \shape start at 0pt
\newdimen\shapecompare % Let there be the dimension \shapecompare
\newcommand{\shifter}[1]{% If \shape is less than the width of the input of \shifter, then make \shape equal to the width of the input. Otherwise, do nothing.
\settowidth\shapecompare{#1}%
\ifdimless{\shape}{\shapecompare}%
{\setlength{\shape}{\shapecompare}}%
{}%
}%
\begin{document}
% At this moment (namely, the very beginning of the document), I would like to make use of whatever value \shape will end up at by the end of the code (namely, by the end, \shape = the width of the words ``Yes, sir, I will be there.'').
\hspace{\shape}Hello
\shifter{Hello}
\hspace{\shape}Hello
Hello
\shifter{Yes, sir, I will be there.}
\hspace{\shape}Hello
Yes, sir, I will be there.
\end{document}
Note: Stephen's answer (https://tex.stackexchange.com/a/55432/277990) to the question How to retrieve a value which is set later on in the document? seems like it could be relevant to my situation, but when I tried to replace its use of \setvalue and \getvalue into the corresponding terms in my situation, I couldn't get it to work --- and on top of that I'm not sure how the stuff about .aux works.

