Lua Questions
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Thread data type in Lua.
Please, explain what "thread" data type is and what it needs for.
Re: Thread data type in Lua.
You have read the http://lua-users.org/wiki/ThreadsTutorial ?Andrey01 wrote:Please, explain what "thread" data type is and what it needs for.
'My' wiki-pages: Build-a-home - basic-robot - basic_robot_csm - basic-machines - digtron - xdecor -
Map-Database
Map-Database
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Re: Thread data type in Lua.
No, didn`t read there. I read on lua.org manual (on Russian language). I`ll read there, too, thanks.hajo wrote:You have read the http://lua-users.org/wiki/ThreadsTutorial ?Andrey01 wrote:Please, explain what "thread" data type is and what it needs for.
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Lua Questions
I read Lua manual and i would like to check my knowledge that i got while i was reading that. Where can i find a book that i could solve problem in on Lua?
- rubenwardy
- Moderator
- Posts: 6972
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
Re: A book with tasks in Lua
There's Minetest-specific tasks at the end of most chapters here: http://rubenwardy.com/minetest_modding_book/
Re: A book with tasks in Lua
Rosettacode is a wiki with a lot of programming-tasks,Andrey01 wrote:Where can i find a book that i could solve problem in on Lua?
solved in many programming-languages, and lua is among them.
You can look at existing solutions, and contribute your own.
Also, Trainsported is a game/simulation where you have to write programs in lua.
'My' wiki-pages: Build-a-home - basic-robot - basic_robot_csm - basic-machines - digtron - xdecor -
Map-Database
Map-Database
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Re: A book with tasks in Lua
Thanks, but there are Minetest tasks that need the knowledge of Minetest API to solve them. But i need just Lua tasks with various themes as if... elif... else... construction, working with varyables, massives, tables and etc... also some cycles for, while, repeat...rubenwardy wrote:There's Minetest-specific tasks at the end of most chapters here: http://rubenwardy.com/minetest_modding_book/
Thanks, but if honestly i`m confused in that wiki and i can not find good tasks. And i would like tasks to be distributed themes and if it would be possible to solve online.hajo wrote:Rosettacode is a wiki with a lot of programming-tasks,Andrey01 wrote:Where can i find a book that i could solve problem in on Lua?
solved in many programming-languages, and lua is among them.
You can look at existing solutions, and contribute your own.
Also, Trainsported is a game/simulation where you have to write programs in lua.
- v-rob
- Developer
- Posts: 970
- Joined: Thu Mar 24, 2016 03:19
- GitHub: v-rob
- IRC: v-rob
- Location: Right behind you.
Re: A book with tasks in Lua
Just wanted to point out that that is Python syntax (And maybe the syntax of other languages as well). Lua uses elseif, not elif.Andrey01 wrote:... elif...
Re: A book with tasks in Lua
Start looking at simple tasks, eg. Conditional_structures.Andrey01 wrote:i need just Lua tasks with various themes as if... for, while, repeat...
i`m confused in that wiki and i can not find good tasks.hajo wrote:Rosettacode is a wiki with a lot of programming-tasks
There, look at the section about that theme/task/problem, done in lua.
You can compare that section with other languages, eg. C, Python, etc.
Do the same for Loops/For, etc.
Currently, there are 872 Programming_Tasks,
and of these 563 have a section/solution.in lua.
So, there are 186 unsolved task left for you to do :)
Maybe look at Angle_difference_between_two_bearings,
or Averages/Mean_time_of_day.
But I recommand to just read & understand existing solutions,
and try to do some of them on your own.
Some online-IDEs that support lua:i would like tasks .. possible to solve online.
* http://www.lua.org/demo.html
* http://codepad.org/
* https://ideone.com/
'My' wiki-pages: Build-a-home - basic-robot - basic_robot_csm - basic-machines - digtron - xdecor -
Map-Database
Map-Database
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Problem with massive printing in Lua.
I wrote a code:
and tried to print the massive after some calculations, but i got it:
But i wanted to print the massive with all elements that it has currently! Why does it happen and what does this mean?
And the same thing happens with tables when they are been printing.
Code: Select all
mas = {"dungeon_master", "tree", "sand", "oerkki"}
if #mas == 4 then
mas[5] = "stone"
elseif #mas == 5 then
mas[6], mas[7] = "cow", "sheep"
end
print(mas)
Code: Select all
table: 0x11e7e10
And the same thing happens with tables when they are been printing.
- Krock
- Developer
- Posts: 4650
- Joined: Thu Oct 03, 2013 07:48
- GitHub: SmallJoker
- Location: Switzerland
- Contact:
Re: Problem with massive printing in Lua.
This means that converting a table to string returns some kind of memory address where the table is saved in Lua. Use " dump() " instead:
Code: Select all
print(dump(mas))
Look, I programmed a bug for you. >> Mod Search Engine << - Mods by Krock - DuckDuckGo mod search bang: !mtmod <keyword here>
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Ways for input of data.
I tried to solve one task. There are two numbers (A and B). I need to print them all with using for loop. For example, in oprder to input random numbers (in this case A and B) there are function input() in Python. But how to do it in Lua? Any like functions or else to input those numbers?
And by the way i`ve noticed there is input() function in Lua, but it is intended for files.
Here is a example:
And by the way i`ve noticed there is input() function in Lua, but it is intended for files.
Here is a example:
Code: Select all
number1 = 1 -- [[i need to give a value directly in the code itself.
In Python i could instead it to write just: number1 = input()]]
number2 = 10
for i = number1, number2 do -- i need to look over all numbers from 1 to 10 here
print(i) -- and then to print each of them
end
Re: Lua Questions
Do something like:
Code: Select all
input = {"first", "second", "third" }
for _, v in pairs(input) do
print(v)
end
- rubenwardy
- Moderator
- Posts: 6972
- Joined: Tue Jun 12, 2012 18:11
- GitHub: rubenwardy
- IRC: rubenwardy
- In-game: rubenwardy
- Location: Bristol, United Kingdom
- Contact:
Re: Lua Questions
Merged this all into one thread, as a topic every day with a single reply was a bit much.
Here's the documentation for reading standard in: https://www.lua.org/pil/21.1.html
Use io.read():
Or for multiple:
Andrey01 wrote:there is the function input() in Python. But how to do it in Lua? Any like functions or else to input those numbers?
Here's the documentation for reading standard in: https://www.lua.org/pil/21.1.html
Use io.read():
Code: Select all
local number1 = io.read("*number")
Code: Select all
local number1, number2 = io.read("*number", "*number")
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Re: Lua Questions
I was trying to rewrite my cube_nodes mod. I wanted to write registration of blocks simpler than huge code was earlier. But here`s an error. It says on line:79 table index is nil. Why so? Why is it nil? See my code below.
- Andrey01
- Member
- Posts: 2574
- Joined: Wed Oct 19, 2016 15:18
- GitHub: Andrey2470T
- In-game: Andrey01
- Location: Russia, Moscow
Re: Lua Questions
Please help me somebody, and here is a error:
Download my mod:
Code: Select all
2018-04-12 21:39:45: ERROR[Main]: ModError: Failed to load and run script from /home/user/.minetest/mods/cube_nodes/init.lua:
2018-04-12 21:39:45: ERROR[Main]: /home/user/.minetest/mods/cube_nodes/nodes.lua:79: table index is nil
2018-04-12 21:39:45: ERROR[Main]: stack traceback:
2018-04-12 21:39:45: ERROR[Main]: /home/user/.minetest/mods/cube_nodes/nodes.lua:79: in main chunk
2018-04-12 21:39:45: ERROR[Main]: [C]: in function 'dofile'
2018-04-12 21:39:45: ERROR[Main]: /home/user/.minetest/mods/cube_nodes/init.lua:5: in main chunk
2018-04-12 21:39:45: ERROR[Main]: Подробная информация в debug.txt.
Who is online
Users browsing this forum: No registered users and 6 guests