Because ( / esp ) means that esp is a local variable,
and the local variable is erased from memory when c:test finishes its function,
so it is used to prevent confusion when a variable called esp is used elsewhere.
Without this, we would have to come up with new, unique and long variable names every time.
You can simply replace ( / esp ) with ( ) to keep one dwg file loaded.
but, even if you change that.
(setq esp (getreal)) will specify a new one with user input every time.
this situation is keep and bring esp just before (getreal)
but not open it. and then replace with new value. It's like didn't bring it.
so, you can make another variable to store esp as a global variable,
and remove 1 from initget to use the previous value with no response (input space bar).
like this below
(defun c:test ( / esp )
(initget (+ 2 4))
(if (setq esp (getreal (strcat "\nEnter value (or Space Bar < Prev. Value = " (rtos oldesp 2 2) " >)")))
(setq oldesp esp)
(setq esp oldesp)
)
(setq valor (* 10 esp))
(princ valor)
(princ)
);fin defun
However, if you write it like this, you will get an type error.
Because the type of global variable oldesp has never been specified, but rtos has been used. rtos has limitations on the types that can be input.
so, you can change like this
The first value is set to 10, and when user input is received, it is changed to that value from then on.
(setq oldesp 10)
(defun c:test ( / esp )
(initget (+ 2 4))
(if (setq esp (getreal (strcat "\nEnter value (or Space Bar < Prev. Value = " (rtos oldesp 2 2) " >)")))
(setq oldesp esp)
(setq esp oldesp)
)
(setq valor (* 10 esp))
(princ valor)
(princ)
);fin defun
or like this
The first value comes out as < Prev. Value = nil >, but since (vl-princ-to-string) is not as picky as rtos, no error occurs
and when user input is received, it is changed to that value from then on.
(vl-load-com)
(defun c:test ( / esp )
(initget (+ 2 4))
(if (setq esp (getreal (strcat "\nEnter value (or Space Bar < Prev. Value = " (vl-princ-to-string oldesp) " >)")))
(setq oldesp esp)
(setq esp oldesp)
)
(setq valor (* 10 esp))
(princ valor)
(princ)
);fin defun