Jump to content

-1.#IND (X/0)


'LinKin

Recommended Posts

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.

Link to comment

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

Link to comment
  
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.

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