ScriptSpot home

Forum topic · General Scripting

variable change within Funcitons

By JokerMartini · 2011-09-01

Description

This example was made unique for this post.
I want to change out a variable within a function and it does not seem to work....
How would I got about changing out the variable so when the function is run it evaluates as well as stores the value into the corresponding variable.


local posX = undefined
local posY = undefined
local posZ = undefined

fn fnCopy dir var = (
if selection.count == 1 do (
obj = selection[1]
var = obj.pos[dir]
)
)

fnCopy 1 posX
fnCopy 2 posY
fnCopy 3 posZ

Comments (2)
JokerMartini

I'll have to look it up

Thank you for the quick response Anubis,
You're great at quickly responding to questions with solutions.
I'll have to look up the by-referencing.
I'm assuming that is what it's called in the help file as well.

I'll post my script after I make it to show you what I was after. I'd love to get your input on ways that you would possibly change about it.

Thanks
JokerMartini

Panayot Karabakalov

using "by-reference" variable

example:

(
local axPos

fn getAxisPos ax &ref = (
	if selection.count == 1 do (
		obj = selection[1]
		ref = obj.pos[ax]
	)
)

getAxisPos 1 &axPos
)

but as may guess you'll need 3 ref-arguments to put out to 3 variable outside the function, i.e. something like:

(
local posX, posY, posZ

fn getObjPos obj &ref1 &ref2 &ref3 = (
	local pos = obj.pos
	ref1 = pos.x; ref2 = pos.y; ref3 = pos.z
)

if IsValidNode selection[1] do
	getObjPos selection[1] &posX &posY &posZ
)