MTA Team Lpsd Posted December 13, 2016 MTA Team Posted December 13, 2016 (edited) I've got this simple require code, and in my console it's returning as a boolean, instead of returning with the function ready to use server.lua: function checkStars(thePlayer) local wantedLevel = getPlayerWantedLevel ( thePlayer ) -- get the wanted level of the player return wantedLevel end theFunctions = { "checkStars" } -- list of functions available for other files, returned when using "require" return theFunctions Another .lua file, in the same directory: getMain = require("server") function getStars(quitType) local gotStar = getMain.checkStars(source) end addEventHandler ( "onPlayerQuit", getRootElement(), getStars ) And the error from console: ERROR: xml2\serverLogin.lua:4: attempt to index global 'getMain' (a boolean value) I know this means the file either isn't being loaded (false), or for some reason "theFunctions" isn't being returned. Any thoughts? Edited December 13, 2016 by LopSided_
tosfera Posted December 13, 2016 Posted December 13, 2016 I'm not sure, I haven't done this at all in MTA yet but try to make the values in your theFunctions table non-string based. Why would they use a string to call a function?
MTA Team Lpsd Posted December 13, 2016 Author MTA Team Posted December 13, 2016 34 minutes ago, tosfera said: I'm not sure, I haven't done this at all in MTA yet but try to make the values in your theFunctions table non-string based. Why would they use a string to call a function? Literal facepalm. I don't know why I'd put it like that. I tried this however and still no luck: theFunctions = {} function theFunctions.checkStars(thePlayer) local wantedLevel = getPlayerWantedLevel ( thePlayer ) -- get the wanted level of the player return wantedLevel end return theFunctions
tosfera Posted December 13, 2016 Posted December 13, 2016 I'm currently working with some pretty complex things on work in angular but that did give me an idea. Try it like; theFunctions = { }; theFunctions.checkStars = function ( thePlayer ) return getPlayerWantedLevel ( thePlayer ); end return theFunctions
MTA Team Lpsd Posted December 13, 2016 Author MTA Team Posted December 13, 2016 (edited) Weird, nothing changed with that either. Maybe it's the way I'm calling it, by doing "getMain.checkStars(source)" Edit: Yep, it was. server.lua: theFunctions = {} function theFunctions:checkStars(thePlayer) local wantedLevel = getPlayerWantedLevel ( thePlayer ) -- get the wanted level of the player return wantedLevel end return theFunctions other .lua file in same directory: require("server") -- no need to put in variable local gotStar = theFunctions:checkStars(source) -- use table name with function in Edited December 13, 2016 by LopSided_
tosfera Posted December 13, 2016 Posted December 13, 2016 That should work. even though functions should be called with a ":" but it's inside a table so the dot should work.. try using a ":" instead? 1
MTA Team Lpsd Posted December 13, 2016 Author MTA Team Posted December 13, 2016 Yeah that works perfectly now, I'd missed changing the "." to ":" by mistake
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