pcall() doesnt work?

  • TPT_PL
    11th Sep 2016 Member 1 Permalink
    Why this doesn't work?

    nuclear = {}
    for i=1, 255 do
    if pcall(elem.property(i, "MenuVisible")) then
    if elem.property(i, "MenuSection") == 10 then
    nuclear[i] = i
    end
    end
    end
  • LBPHacker
    11th Sep 2016 Developer 0 Permalink

    Because pcall is not try-catch. If it *was* like that, you'd have to use block opening/closing tags such as do/end. pcall is a function that calls other functions. You just happen to be able to pass anonymous functions around in Lua:

     

    local nuclear = {} -- don't forget the local
    for i = 1, 255 do
        pcall(function() -- we just create an anonymous function here
            -- this is not C, 0 evaluates to true (because it's nor false nor nil)
            if elem.property(i, "MenuVisible") == 1 and elem.property(i, "MenuSection") == 10 then
                nuclear[i] = true -- why store the ID twice?
            end
        end)
    end