Visual LISP, AutoLISP and General Customization
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Variable reset

4 REPLIES 4
Reply
Message 1 of 5
kulfi
397 Views, 4 Replies

Variable reset

Hi, when i am clicking first button with Key "Edit1" the value store R is 1
when i click button with key edit2 the valuse stored to W is 2
the problem here is that values are not reset like when i close the program the values should be nil for both how can i do that Please guide with any example.
thanks
(action_tile "edit1" "(setq R 1)")
(action_tile "edit2" "(setq W 2)")

(if (= R 1) (RBox))
(if (= W 2) (Box))
Kulfi
Electronics Engineer

Pind Saudi Arabia



4 REPLIES 4
Message 2 of 5
Moshe-A
in reply to: kulfi

Kulfi,

you need to learn more about Local variables & Global variables

by default in autolisp a variable is Global and maintain it's last value
even your program is finihed unless you define it as Local variable

example

{code}

(defun some_func (x / A)

; all variables after '/' are locals in (some_func)
; defining variable as local will automaticlly set them
; to nil when the function is evaluate
; local variable scope is only inside the
; function they are defined
; they will vanish when the function is done

(setq A 2)
(setq A (+ x A))
(princ A); local A is 7
)

(setq a 5) ; define a as global
(some_func a)
(princ a) ; global a is still 5

{code}

hope this helps
Moshe
Message 3 of 5
Kent1Cooper
in reply to: kulfi

I don't know what else you have going on around this, and I haven't used (action_tile), so I'm not sure of the syntax, but I wonder: is there some reason not to just do this, and avoid the variables entirely?

(action_tile "edit1" "(RBox)")
(action_tile "edit2" "(Box)")

If there is, and also some reason you can't do it by localizing the variables as moshe-a suggests, then maybe you can solve it this way:

{code}
(if (= R 1)
(progn
(RBox)
(setq R nil)
); end progn
); end if
(if (= W 2)
(progn
(Box)
(setq W nil)
); end progn
); end if
{code}

--
Kent Cooper

kulfi wrote...
....values are not reset like when i close the program the values should be nil for both....

(action_tile "edit1" "(setq R 1)")
(action_tile "edit2" "(setq W 2)")

(if (= R 1) (RBox))
(if (= W 2) (Box))
Kent Cooper, AIA
Message 4 of 5
kulfi
in reply to: kulfi

What i want is that when i select any tile the value is 1 but this value is there even if i close the program and execute again.
what i want is that when i select the any tile the value should be one and immediatly i am out of the program the value should be 0.
thanks
Kulfi
Electronics Engineer

Pind Saudi Arabia



Message 5 of 5
stevor
in reply to: kulfi

Then you could change the lsp that calls and loads variables into the dcl, to load what you want.

If you want to store the last assigned values, then they must be stored somwewhere, and fetched before calling the dcl.
S

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost