T
T
Tera Incognita2020-12-05 23:23:35
Game development
Tera Incognita, 2020-12-05 23:23:35

How to ask Lua input from the user?

In Python it would be like this:

a=input("Кто ты? и как тебя Зовут?:")
print(a)


In Scratch , like this.
5fcbebf0228f3027658891.png

How to do it in Lua?

io.write('Hello, what is your name? ')
local name = io.read()
io.write('Nice to meet you, ', name, '!\n')

So I tried - it does not work, there is no external library and it cannot be connected, I work in Coregames.

How to open a dialog box in Lua and append to the response?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dollar, 2020-12-07
@Lunali

Lua is an embeddable language.
Therefore, you need to look not at Lua itself, but at the API provided by the external environment - Coregames, as well as at the components that are present there and that can be used. This environment determines what the input window will look like, how many buttons there will be, which Lua function is responsible for input, and so on. Internal features of the Lua language can be changed or removed altogether, depending on how it is embedded, protected, etc. It is very common to disable the io and os libraries to limit interactions with the system and improve security.
Documentation for Coregames is here: docs.coregames.com
It may well be that Coregames does not require the user to enter a string at all. Then you have to make your own decision. Namely, draw an input field, read individual keys, and form a string from them. Another option is to draw buttons on the screen so that the user can poke them with the mouse, gradually forming a line. But this is just an assumption that there is no support for string input. The exact answer can be obtained after reading the entire documentation.
For example, the game Tabletop Simulator also has a built-in Lua language. The input field, as such, is not provided there. But on the other hand, through the event, you can "catch" the messages entered by the players in the chat. Players also have the ability to give objects names and descriptions - they can also be read using the input field as an alternative. These components are determined by the environment, that is, by this game, and the Lua language cannot create them from nothing or remove them from the game, but Lua has access to them, can get values ​​​​from there or write new values ​​\u200b\u200bto them. Thus, Lua uses those components that are defined by the environment and that are described in the documentation.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question