I have a script with several functions. I think I understand how to feed something into a function variable, example:
function myfunction(var1, var2){
blah blah;
return myresult1, myreult2;
}
myfunction(data1, data2);
How many variables can a function return? Some of my functions need to return multiple variables to use in other functions. What's the best way to do that? I'm having trouble getting one function to output something to another function.
Functions, getting data in and out.
Moderator: Paul Tuersley
Never mind, I think I have it working now. I put my variables in an array and then just pulled what I needed out of the array when sending variables to the next function. Is that the best way to do this?
-
- Posts: 114
- Joined: March 10th, 2005, 5:50 am
- Location: London, UK
- Contact:
Hi Byron,
An array is good way to send through complex data. Another option would be to use an Object. You can create one using the Object object:
or shorthand:
or you could create a class constructor, but thats probably too much info for now.
One of the advantage of using an object over an array is that its easier to remember properties of the object, rather than indices of an array.
Try this to test:
Cheers,
Dave
An array is good way to send through complex data. Another option would be to use an Object. You can create one using the Object object:
Code: Select all
data=Object()
data.name="Ben"
data.data="On wednesdays I go shopping"
Code: Select all
var data={name:"John",data:"Once upon a time"}
One of the advantage of using an object over an array is that its easier to remember properties of the object, rather than indices of an array.
Try this to test:
Code: Select all
function editData(obj){
obj.data=5
obj.name="Dave"
return obj
}
var data={name:"John",data:"Once upon a time"}
alert([obj.name,obj.data])
data=editData(data)
alert([data.name,data.data])
Cheers,
Dave
That's good to know, thanks!
-
- Posts: 114
- Joined: March 10th, 2005, 5:50 am
- Location: London, UK
- Contact:
Glad to be of help!
Out of interest - what sort of 3d do you do? Which package are you using?
TTFN, Dave
Out of interest - what sort of 3d do you do? Which package are you using?
TTFN, Dave