Objects inside functions

I have an object defined as global in my main.lua, in my library.lua I have defined a global function called doSomthing(). In the main.lua I’m trying to change the property of that object but for some reason I always get the following error:-
Attempt to set the value of ‘myobject’ a nil value.

I would appreciate your help in this matter.

[import]uid: 11038 topic_id: 3866 reply_id: 303866[/import]

I don’t think you’ve explained that right. You’ve said your object is in main.lua and you’re trying to change it in main.lua

Anyway it’s only global if you use the global _G

ie _G.something = “whatever”

Otherwise you’ll probably need to pass a reference to main into library eg library.root = self (in main, if this doesn’t work use a setter function eg setRoot), then root.myMainObject = “whatever” in your library function [import]uid: 6645 topic_id: 3866 reply_id: 12049[/import]

Im sorry, but what i meant is the variable i want to access is inside my library.lua.
I didnt understand what u’ve explained with regard to a setter function. Would u give me a brief example so i can understand properly

Thanks [import]uid: 11038 topic_id: 3866 reply_id: 12053[/import]

main.lua
[lua]local library = require(“library”)
library.setX(50)
print(library.getX()); – => 50[/lua]

library.lua
[lua]…

local _x = 0

function setX(n)
_x = n
end
function getX()
return _x
end[/lua] [import]uid: 6645 topic_id: 3866 reply_id: 12132[/import]

also you need to define your problem more clearly. where is your object defined. where are you trying to access it and what are you trying to do to it?

[import]uid: 6645 topic_id: 3866 reply_id: 12133[/import]