ScriptSpot

Forum topic · General Scripting

stop loop or script

By Mrjacks2o · 2015-09-01

Description

Hi Everyone this is my script and what i cant seem to figure out is how to stop the script right after it gives the messagebox "please Redo Balls" so it doesn't play to SPH2

(
)
obj = $SPH1
if obj == undefined then messagebox "please Redo Balls"
else
(
selectmore $SPH1
)
obj = $SPH2
if obj == undefined then messagebox "please Redo Balls"
else
(
selectmore $SPH2
)

thanks in advance.

Comments (6)

Mrjacks2o · 2015-09-05

thanks everyone!!!!

`

pixamoon · 2015-09-01

if you use loop "for ... do...." you can use just "exit"

it can look like this:


objArray = #($SPH1, $SPH2)
for obj in objArray do 
(
	if obj == undefined then 
		(
		messagebox "please Redo Balls"
		exit
		)
	else
	selectmore obj
)

cheers,
Pixamoon

.

miauu · 2015-09-01

Regarding maxscript reference file using the EXIT command must be avoided as much as possible, so you can use:


objArray = #($SPH1, $SPH2)
stopLoop = false
for obj in objArray while stopLoop == false do 
(
	if obj == undefined then 
	(
		messagebox "please Redo Balls"
		stopLoop = true
	)
	else
	        selectmore obj
)

`

pixamoon · 2015-09-02

good to know :)

I checked maxscript help and found only that "exit" can be extremely slow, but didn't find any info to avoid it "as much as possible". Can you post a link to that ?

best,
Pixamoon

.

miauu · 2015-09-02

The exact words in maxscript reference are "Do not use return, break, exit or continue."

Here is the link.

`

pixamoon · 2015-09-02

ah, that's true

This is in chapter "How To Make It Faster" - how to make scripts faster

There is also "Disable Undo system when possible" and more...

But sometimes is good to use undo :)

Of course is good to know those functions can make scripts slower.

Thanks,
Pixamoon