FUNExtreme Posted May 3, 2010 Share Posted May 3, 2010 Hello, I have a problem getting a boolean out of a map file and then using it in a function -- Blah blah (loop here) local newTeam = createTeam(tostring(getElementData(s, "name")), tonumber(getElementData(s, "colourR")), tonumber(getElementData(s, "colourG")), tonumber(getElementData(s, "colourB"))) setTeamFriendlyFire(newTeam, tostring(getElementData(s, "friendlyFire"))) but it always says bad argument, I tried, tonumber, tostring and all that but I actually need toboolean wich doesn't exist in MTA lua. The .map contains .... friendlyFire="true" .... I have allready made a workaround to fix this problem but I want to know if it is possible to do it like I state above. (Using a boolean in the .map file and then just getting it) Link to comment
dzek (varez) Posted May 3, 2010 Share Posted May 3, 2010 tostring ... returns .. STRING --- [sUPRISE!!] and you need boolean toboolean should do the job (im not sure about its name, but it was something like that?) or just remove that tostring - and it should work Link to comment
robhol Posted May 3, 2010 Share Posted May 3, 2010 tostring ... returns .. STRING --- [sUPRISE!!] and you need booleantoboolean should do the job (im not sure about its name, but it was something like that?) or just remove that tostring - and it should work There's no toboolean.. if it returns a string, check whether it's "true". For extra "security" you can also check if it's "false". (If it's neither, you're obviously getting something unexpected.) Link to comment
FUNExtreme Posted May 3, 2010 Author Share Posted May 3, 2010 As I wrote before I checked all the options allready but here are the answers tostring returns correctly wich means that it shows "true" or "false" when used in outputDebugString using nothing but just the getElementData also returns "true" or "false" when used in outputDebugString although when I use it in setTeamFriendlyFire it gives bad argument. and as robhol stated (so did I in the first post) toboolean doesn't exist Link to comment
dzek (varez) Posted May 3, 2010 Share Posted May 3, 2010 and as robhol stated (so did I in the first post) toboolean doesn't exist hmm, maybe, i never need that, but in lua's manual i found something like that, thats why i wrote it here Link to comment
robhol Posted May 3, 2010 Share Posted May 3, 2010 It doesn't exist... However, for example, you could do something like function toboolean(x) if x == "true" then return true; end if x == "false" then return false; end error("toboolean: unexpected input: " .. tostring(x) ); end Link to comment
karlis Posted May 3, 2010 Share Posted May 3, 2010 function from dxspeedometer resource: function toboolean(bool) if bool=="true" or bool==1 or bool==true then return true end return false end Link to comment
Dark Dragon Posted May 3, 2010 Share Posted May 3, 2010 -- Blah blah (loop here) local newTeam = createTeam(tostring(getElementData(s, "name")), tonumber(getElementData(s, "colourR")), tonumber(getElementData(s, "colourG")), tonumber(getElementData(s, "colourB"))) setTeamFriendlyFire(newTeam, tostring(getElementData(s, "friendlyFire"))=="true") and if you change the map file to friendlyFire="[true]" this should be enough: -- Blah blah (loop here) local newTeam = createTeam(tostring(getElementData(s, "name")), tonumber(getElementData(s, "colourR")), tonumber(getElementData(s, "colourG")), tonumber(getElementData(s, "colourB"))) setTeamFriendlyFire(newTeam, getElementData(s, "friendlyFire")) 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