Getting input from the user in Lua
Use io.read() Beware that the function can be customised with different parameters. Here are some examples.
Use io.read() Beware that the function can be customised with different parameters. Here are some examples.
In Lua 5.2 the best workaround is to use goto: This is supported in LuaJIT since version 2.0.1
Have a look at this page http://lua-users.org/wiki/StringRecipes: Then use
Use the tonumber function. As in a = tonumber(“10”).
You should convert your string to a number, if you know for sure that it should be a number, and if there is no reason for it to be a string. Here’s how to do a comparison for a range: Notice the and. Most programming languages don’t expand the form x < y < z … Read more
Feel free to browse the Lua Wiki on table serialization. It lists several ways on how to dump a table to the console. You just have to choose which one suits you best. There are many ways to do it, but I usually end up using the one from Penlight:
You already have the solution in the question — the only way is to iterate the whole table with pairs(..). Also, notice that the “#” operator’s definition is a bit more complicated than that. Let me illustrate that by taking this table: According to the manual, any of 3, 5 and 9 are valid results for #t. The only … Read more
pairs() and ipairs() are slightly different. pairs() returns key-value pairs and is mostly used for associative tables. key order is unspecified. ipairs() returns index-value pairs and is mostly used for numeric tables. Non numeric keys in an array are ignored, while the index order is deterministic (in numeric order). This is illustrated by the following … Read more
I’m trying to make a simple script for a game, by changing the time of day, but I want to do it in a fast motion. So this is what I’m talking about: and so on. How would I go about doing this?
Try lalarm, here: http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/ Example (based on src/test.lua): Output: