Jump to content

Getting a boolean with getElementData


Recommended Posts

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
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

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

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

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
-- 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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...