Wherry Posted January 23, 2012 Share Posted January 23, 2012 (edited) Hello! Can you guys help me? I have file a.lua and b.lua and i need to call functions from b.lua in a.lua. How to do it? btw: I already tried dofile() loadfile() (MTA says that it's unsafe functions). also i tried to define variables as global: b.lua: x = "Hello World" a.lua outputChatBox(x) This example outputs error too. And ofcourse i tried to use triggerEvent + addEvent but it's bad. Thank you! Edited January 23, 2012 by Guest Link to comment
Al3grab Posted January 23, 2012 Share Posted January 23, 2012 is they are in the same side ? Link to comment
Wherry Posted January 23, 2012 Author Share Posted January 23, 2012 is they are in the same side ? Yes ofcourse. Both files are client-side Link to comment
BriGhtx3 Posted January 23, 2012 Share Posted January 23, 2012 Use global variables and settings files Link to comment
BriGhtx3 Posted January 23, 2012 Share Posted January 23, 2012 (edited) first file : function abc() number1 = 60 end addEventHandler("onClientResourceStart",getRootElement(),abc) second file : function bbc() outputChatBox(tostring(number1)) end addCommandHandler("text",bbc) Edited January 23, 2012 by Guest Link to comment
Kenix Posted January 23, 2012 Share Posted January 23, 2012 xthepr0mise,Your getRootElement is wrong( nil ) in first file. Should be root or getRootElement( ). Link to comment
DiSaMe Posted January 23, 2012 Share Posted January 23, 2012 If you make a global variable/function in one script, it will be available in another script of the same resource on the same side. also i tried to define variables as global:b.lua: x = "Hello World" a.lua outputChatBox(x) Are you sure that code in a.lua was executed after b.lua, not before it? xthepr0mise,Your getRootElement is wrong( nil ) in first file.Should be root or getRootElement( ). No, it's not nil. If it was nil, then getRootElement() would be wrong too because nil value can't be called. getRootElement is a function value. Link to comment
Kenix Posted January 23, 2012 Share Posted January 23, 2012 Ah,yeah this is function variable but not called . Anyway addEventHandler return false. Are you sure that code in a.lua was executed after b.lua, not before it? Better use event onResourceStart ( if server side ) and call function. And do not think about such issues. Link to comment
BriGhtx3 Posted January 23, 2012 Share Posted January 23, 2012 Fixed it. Sorry, I always type it in the browser and dont check it afterwards. 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