Notifications
Clear all

[Closed] Question : does parentheses change script behavior?

hi i wrote this code which do offset a selected spline twice and delete the two new segmets that connects them here is the code :

aao = $

w = 3.5

fn deleteoffset spl = (

convertToSplineShape spl

subobjectLevel = 2

todel = numSegments spl 1

todel2= todel/2

sel = #()

setSegSelection spl 1 #()

for i = 1 to todel2 do (

append sel i

)

append sel todel

setSegSelection spl 1 sel

splineOps.delete spl

updateshape spl

)

aa = copy aao

spl = getSplineSelection aa

allspl = numSplines aa

for i = allspl to 1 by -1 do (

if i != spl[1] do (

deleteSpline aa i

)

)

applyOffset aa w

select aa

deleteoffset aa

aa2 = copy aa

applyOffset aa2 (w *-1)

select aa2

deleteoffset aa2  

here is the result :
03

this is when things get strange if i add two parentheses at the last section of the code :

(

applyOffset aa w

select aa

deleteoffset aa

aa2 = copy aa

applyOffset aa2 (w *-1)

select aa2

deleteoffset aa2

)

this is the result :
04

can anybody explain it and suggest a fix ? i want to add this code to a forloop or inside a macroscript.
thanks

1 Reply

Adding brackets around code changes the scope.
So you are throwing all of the variables out of global scope by wrapping that section in parentheses.
Mark up your local variables with the local keyword to make sure you don’t get naming conflicts or scoping issues:

local var1 = 1