• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community

Search results

  1. H

    Adding a default value to a table makes the ipairs method goes in a infinity loop

    Hello, I wanna know if this thing is something that could be fixed or there is a logical reason to have it, but if you add a "default value" to a table, like in other programming languages, for example a table that contains integer, a not declared index returns 0 instead of nil: list = <table...
  2. H

    Floating numbers print

    Try using string.format to see what's going on, in my case I did: print(string.format("%.20f", 298+2/3)) print(string.format("%.20f", 128+4/9*384)) print(298+2/3 == 128+4/9*384) And got: 298.66666666666668561447 298.66666666666662877105 false
  3. H

    Variable can't decide what it is

    The thing in the second, the function type returns a string and you are comparing with a non-string values: -- Bad print(type(event.params.var1) == string) print(type(event.params.var1) == table) -- Good print(type(event.params.var1) == "string") print(type(event.params.var1) == "table") So you...
  4. H

    I wanna handle errors, but a program I'm using makes it difficult for me

    Hello, I'm using Warcraft 3 and I wanna handle better the errors, because it don't have its own event log I wanna create it myself to improve its debugging, but I have problems: It doesn't print the errors or warns unless you use "xpcall(func, print)", I can do that but it will make the errors...
  5. H


    I don't know what do you mean, because this: for i = 1, 10 do print(math.random(-10, 10)) end printed me this: -6 5 5 -7 6 -10 -10 -10 4 4
  6. H

    Lua error. My file name is trans.lua. the error is - trans.lua:1: '=' expected

    Hey, why did you add the ';'?, lua don't use it. Edit: Nah, you can use it, I think is your code convention.
  7. H


    Do you know that the table is the variable "console" and not its childs?, but you can't do: console[1] = something Because console[1] is not a table, in fact, is not anything, the correct would be: console = {} console[1] = {} console[1].data = "a string" -- Or console = {{}} -- a table stored...
  8. H

    using global Variable in IF-THEN

    What if @Bobbie wanna use the 'require' function?
  9. H

    How to debug in Intellij

    Is not that a java compiler?
  10. H

    Lua self.<fieldName> not working as expected

    Because you defined the function 'addPlayer(player)' with the colon, but you called with just the dot newQueue.addPlayer(player) -- No newQueue:addPlayer(player) -- Yes If you don't know, what the colon does is adding an invisible parameter that is the table itself, basically: function...
  11. H

    How works _G and _ENV and what can I do with them?

    Thank you for the explanation.
  12. H

    How works _G and _ENV and what can I do with them?

    @GavinW I don't know, because I'm not much about reading long texts even if I'm interested in the topic, I do that but is too difficult to me, so I'm not sure in invest 27$ in a book (100 PEN in my country).
  13. H

    How works _G and _ENV and what can I do with them?

    I'm curious to know how they work and the information I found isn't enough so I need a better explanation and also wanna know what can I do with them because I see the programs that use Lua use them to create their global values.
  14. H

    Lua ignoring float type

    The library math have a function called math.type(number) that returns "float" or "integer" depending on the number or nil if is not a number, you can use it to see what is happening.
  15. H

    Ellipses assignment outside of a function?

    Don't you mean the first? because you add an extra comma.
  16. H

    Instance scripts?

    @stetre Interesting, I'm new on this of advanced programming so there is a lot of things I don't know.
  17. H

    Instance scripts?

    I was working in CoreGames for a couple of months, and I'm curious about how it works, basically the scripts can be objects, also can be instanceable, all the same script with its variables and functions, just in different contexts, is like they work as "functions" instead of being the main...
  18. H

    Is there a way to reffer a table itself inside the same table?

    @stetre but there will be a noticeable change if I do that a lot or still insignificant?
  19. H

    Is there a way to reffer a table itself inside the same table?

    Question, the functions rawset and rawget are faster than use the normal "table[key] = value"?, because they act without using the metamethods __index and __newindex respectively.
  20. H

    Is there a way to reffer a table itself inside the same table?

    @stetre Ah ok, I got it. Thanks