Olle Risk Posted September 21, 2015 Share Posted September 21, 2015 Alright so I have two resources A and B, in A I define a variable: local myVariable = nil In B I have a function that creates an object and assign it to a variable, (the function is exported) function makeWindow() local myVariable = guiCreateWindow(blahblahblah) end Now, is it possible to pass myVariable from A to the function in B as an argument, assign the object to the variable defined in A then somehow return it back to A? Why would I do this? Well this object is big and needs to be accessed by multiple resources and I don't wanna include it into all resources, I want it to be owned by the resource that calls the export (A) so that it doesn't get removed once I restart B.Is this possible? Link to comment
Moderators IIYAMA Posted September 21, 2015 Moderators Share Posted September 21, 2015 Objects that are created by scripting are bounded to the resourceDynamicElementRoot. Once that element is destroyed it will take all his children with him. When you stop a resource, the resourceRoot is destroyed, which means that all children bellow are destroyed too. It works like this: resourceRoot resourceDynamicElementRootElements created by scripting getResourceMapRootElement Map elements Wiki: Afaik, you can't edit this with setElementParent. You will have to initialize the elements again once you start it. Link to comment
JR10 Posted September 21, 2015 Share Posted September 21, 2015 -- RESOURCE A local myObject = createObject(...) myObject = exports.B.manipulateObject(myObject) -- RESOURCE B function manipulateObject(object) local anotherObject = createObject(...) return anotherObject end You can send and return any element. So, yes, you can do that. IIYAMA's explanation is irrelevant to your scenario here, if I understood you correctly. Link to comment
Olle Risk Posted September 21, 2015 Author Share Posted September 21, 2015 Thanks JR10, that was similar to what I was looking for, but It's still not exactly what I'm trying to do, let's assume this object is a large image created by guiCreateStaticImage in resource B. Using your example with a few modification, would this work? -- RESOURCE A local myObject = nil myObject = exports.B.manipulateObject(myObject) -- RESOURCE B function manipulateObject(object) object= guiCreateStaticImage(...) return object end I mean, would this let resource A be the owner of this image so that if I restart B this image won't disappear from A? Link to comment
JR10 Posted September 21, 2015 Share Posted September 21, 2015 No, it won't. It will still be destroyed, which, in this case, IIYAMA's explanation is correct. Maybe try telling us what you need to achieve here? Link to comment
Moderators IIYAMA Posted September 21, 2015 Moderators Share Posted September 21, 2015 He could try to create all elements in 1 resource. -- RESOURCE A local myElement = nil local elementCustomName = "HelloWorld!" myElement = exports.B.createElementForResource( elementCustomName, -- a custom name for your element, to prevent multiply elements of the same use. createObject, -- the functions you want to execute bla,bla,bla,bla -- arguments ) -- RESOURCE B local customElementNames = {} function createElementForResource(...) if isElement(customElementNames[elementCustomName]) then return customElementNames[elementCustomName] else local data = {...} local elementCustomName = data[1] table.remove(data,1) local functionInUSe = data[1] table.remove(data,1) local element = functionInUSe(unpack(data)) if element then customElementNames[elementCustomName] = element return element end end return false,"Element failed to create." end As long this(B) is the only resource the is running, it will work. Link to comment
Olle Risk Posted September 21, 2015 Author Share Posted September 21, 2015 Guess I have to find another way then, thanks anyway Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now