'LinKin Posted April 4, 2014 Posted April 4, 2014 Hello, When you try to divide x/0 , it will return this string: -1.#IND So, when that happens, as I'm setting the result of the division as a label's text, I want to make it '0' instead of '-1.#IND'. I'm currently doing it this way: if tostring(myResult) == "-1.#IND" then guiSetText(myLabel, 0) else guiSetText(myLabel, myResult) end And I have 9 more lines like that. I was wondering if it is possible to make it 'easier', for example when you do local myResult = myTable[1] or 0 , so that I don't have extra lines. Thanks.
mint3d Posted April 4, 2014 Posted April 4, 2014 Make a table https://wiki.multitheftauto.com/wiki/Table
cheez3d Posted April 4, 2014 Posted April 4, 2014 You can't divide a number by 0 so n/0=0 is not correct.
'LinKin Posted April 4, 2014 Author Posted April 4, 2014 Yes, it's not correct, but still I don't want to set "-1.#IND" as the label's text. That's for making the kill to death ratio which is kills/deaths. But if the player has 0 deaths... I'll better make it myResult = kills instead of myResult = 0. Anyway, can I do this in one line? Just like when you do: local myResult = myTable[1] or 0. -- Also, How to change the labels' font with a loop? for _,theLabel in ipairs(getElementsByType("gui-label")) do guiSetFont(theLabel, "default-small") end Would it change the font of other resources' labels? Because I remember I did this once to change the font of some labels in the race resource, and it did work. (Despite it was a different resource (folder))
cheez3d Posted April 4, 2014 Posted April 4, 2014 for _,label in ipairs(getElementsByType("gui-label",resourceRoot)) do -- your code end This function also has a startat parameter. It defaults to the root element so it changes all the resources' fonts but you can specify resourceRoot to change only the resource's labels.
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