• Announcement: Lua.org now officially recommends this forum as a meeting place for the Lua community
  • The forum is currently open to new registrations. The registration will close for a short period of time when reaching 500 active members, to upgrade the server resources.

Search results

  1. stetre

    How to loadstring()?

    The third bracket is for passing the argument. I'll break it down into individual steps, so to make it (hopefully) clearer: local a = 1 local f = loadstring("return function(x) local b=x+1 print(b) end") -- step 1 local g = f( ) -- step 2 g(a) -- step 3 At step 1, loadstr returns a function...
  2. stetre

    How to loadstring()?

    You can, however, use loadstring to define functions that accept arguments, and pass the local variable as argument. For example: local a = 1 loadstring("return function(a) local b=a+1 print(b) end")( )(a)
  3. stetre

    metatables do not work!

    At a first glance I see a few. First of all, the metatable must be, well, a table. Secondly, to set it you must use the setmetatable function. Finally, even if you could set the metatable by assigning something directly to the __metatable field, by writing CLASS.mt.__metatable you would set the...
  4. stetre

    Text macro

    The major sources of information about any Lua topic are the reference manual and the book Programming in Lua (see Lua: documentation ). Better if you can get the newest edition (4th) of the latter, otherwise you can find an older edition available for free on the Lua site, which should be good...
  5. stetre

    Text macro

    It is actually pretty flexible and you can do almost everything. The key is to understand how the load function works. Not the easiest topic, but definitely worth studying if you want to leverage the power of Lua. It essentially gives you ways to execute code that you compose at runtime. Such...
  6. stetre

    Text macro

    Lua has a few alternative ways to delimit literal strings, e.g. "hello", 'hello', [[hello]], [=[hello]=] are all valid ways to define a literal string containing the word hello (for more details, see Lua 5.3 Reference Manual ). In the above example, I obtained a string containing valid Lua code...
  7. stetre

    Text macro

    Hi. Lua does not have macros, but there are ways to write functions that in turn define other functions. For example: local function def(name, var) load("function "..name..var.."(val) print('"..var.."', val) end")() end def("Set", "X") -- defines the SetX() function def("Set", "Y") --...
  8. stetre

    how to use goto or continue on LUA?

    According to the Lua history it seems that the goto statement was introduced in version 5.2. The error message is not clear at all, but the problem is most likely this. Perhaps the interpreter assumes that 'goto' is a variable name and infers that the statement 'goto continue' is an assignment...
  9. stetre

    how to use goto or continue on LUA?

    Ah, ok. I assume that line 22 is where the first 'goto continue' is, then. I can't see any syntax error around there. Which version of Lua are you using?
  10. stetre

    how to use goto or continue on LUA?

    The error message tells you that the error is in script named quests.lua. Your code loads and executes a quest.lua script, and then defines a function. Are you sure that you are looking for the error in the right script?
  11. stetre

    Function return value is coming out of a subfunction

    (LOL, the unwanted scared smileys)
  12. stetre

    Function return value is coming out of a subfunction

    I'm not sure I understood how this works, but it seems to me that q:onSuccess() is a callback that meta:GetCharacterTable() sets, and that will be called at some point in time after meta:GetCharacterTable() returns, presumably in a main event loop at the occurrence of a 'success'. If this is...
  13. stetre

    Roblox How to use tonumber, but with text instead of numbers?

    Ok, then. The tonumber() function is of no use here, because it doesn't work with arbitrary strings but only with those that can be converted to a number. Like, for example, the strings "123", "-51", "10e-36", and so on. You can do this instead: you get a reference to the last table in the...
  14. stetre

    Roblox How to use tonumber, but with text instead of numbers?

    Let me elaborate: if you'd like people to spend their efforts to give you help, you'd better help them help you. That is, try to tell them directly what problem are you trying to solve, not what solution you are trying to use. Otherwise you ask them a double, if not triple, effort: reverse...
  15. stetre

    Roblox Mute button not working in Roblox

    As I wrote in the other thread, I don't know much about Roblox so I don't really know what Touched is. I do know something about Lua, though, and if Touched is to be used as in the code you showed above, then: 1) it must be the name of a field of the table game.StarterGui.Mute.TextButton, and...
  16. stetre

    Roblox How to use tonumber, but with text instead of numbers?

    Looks like an XY problem to me.
  17. stetre

    Roblox Mute button not working in Roblox

    It looks like the same problem as in the 'winningplayer' case.
  18. stetre

    Roblox Trouble with Roblox DataStore

    Nope. It's because game.Players.winningplayer is equivalent to game.Players['winningplayer']. That is, the name of the field is the string 'winningplayer'. On the other hand, game.Players[winningplayer] is equivalent to game.Players['player123'], assuming that winningplayer='player123'. What...
  19. stetre

    Roblox Trouble with Roblox DataStore

    Now I get it. Try this: game.Players[winningplayer].leaderstats.Wins.Value = game.Players[winningplayer].leaderstats.Wins.Value + 1 (and if it works, try to understand why game.Players[winningplayer] and game.Players.winningplayer are not the same thing)
  20. stetre

    Roblox Trouble with Roblox DataStore

    I don't know much about Roblox, but if I were you I'd stop doing tests and I'd investigate to understand better how the data is organized. When you do something like this: game.Players.winningplayer.leaderstats.Wins.Value = game.Players.winningplayer.leaderstats.Wins.Value + 1 you are...
Top