Notifications
Clear all

[Closed] How to exit if condition is met

am trying to exit a script when the condition is met

(
if a==1
then
exit
)
else
(
a=1
)

i want to do something like this the first time it runs it skips to and evaluate the (else) lines
then the next run it will evaluate the ( then ) lines and exits without re-evaluating the (else) lines

is this even possible ?

7 Replies

logically it’s the same as:

a = 0
if a != 1 do a = 1

if you re-run the script the a value will be zero again
what am trying to do is to check if its = 1 if not then make it = 1
then when the script is re-run again it will remain 1 and will fall in the condition and exit without the need to evaluate the code under else again
i hope i could explain what am after

a = 0
once_set = false

(
	if a != 1 do
	(
		if not once_set do
		(
			a = 1 
			once_set = true 
		)
	)
	if a == 1 do
	(
		-- ...........
	)
)
(
	global a
	
	if a != 1 do
	(
		a = 1
		-- Evaluate your code here
		print "Hello World"
	)
)

From a function:

(
	global a
	
	fn EvaluateCode = if a != 1 do
	(
		a = 1
		-- Evaluate your code here
		print "Hello World"
	)
	
	EvaluateCode()
)

thanks alot ,can you please explain what once_set is and whats its doing ?

is their any benefit in doing it a function instead ?

1 Reply
(@polytools3d)
Joined: 10 months ago

Posts: 0

No, it’s just a matter of design or organization. It’s up to you to decide it.