[Closed] sending a command to a function?
I find myself using the command “for obj in $selection do” alot in the listener, is there a way to turn that into a function, just for speed?
For example, would something like this be possible?
fn fois command =
(
for obj in $selection do command
)
fois (obj.pos = [0,0,0])
i know if i try this now, it returns obj undefined…obviously because obj is not defined.
Thanks
that in itself wouldnt work…
I would recommend just writing out the loop personally – the overhead of writing that out is pretty minimal, but if you really wanted to go the method way, the two things you could do are:
fn fois command = ( for obj in $selection do (command obj) )
function someaction obj = ( obj.pos = [0,0,0] )
function someotheraction obj = (obj.pos = [10,10,10] )
fois someaction
fois someotheraction
or if thats even too much, do it as an execute
fn fois command = (
for o in $selection do (
global obj = o
execute command
)
global obj = undefined
)
fois "obj.pos = [0,0,0]"
I still wouldn’t really recommend either way though…
The bottom one was more of what i was looking for since my command would change…I was going more for a “strategy pattern” style.
Oh well, thanks.
just learned about this today for another problem, but thought of this post…
you should probably use a mapped function, seems like what its designed for:
mapped function commandA obj = ( obj.pos = [0,0,0] )
mapped function commandB obj = ( obj.pos = [10,10,10] )
commandA $selection
commandB $selection