How to Prompt?
How do I grab the text I said from system.prompt and turn into a variable for text in microscript 2?
How do I grab the text I said from system.prompt and turn into a variable for text in microscript 2?
Essentially, the whole prompt functions cuts down to the following:
system.prompt(display_text, callback)
Here, display_text
is a string that defines what to display when invoking system.prompt
.
callback
is essentially a predefined function you have to pass. I'll just write how it can look.
callback = function(ok, text)
if ok == 1 then
print("User wrote: " + text)
else
print("User wrote nothing!")
end
end
Essentially, the callback has two parameters. ok
is a boolean which will tell if the user actually inputted something, and text
which essentially the... well it's the text the user wrote.
For it to work, you have to input display_text
and callback
both like parameters.
I cant figure out how to put it into screen.drawText?
It's asynchronous, so you can have a variable containing the text to draw.
message = ""
init = function()
system.prompt("Enter text:", function(ok, text)
if not ok then
message = "User canceled prompt"
return
end
message = "User wrote: " + text
end)
end
/* ... */
draw = function()
screen.drawText(message, 0, 0, 15, "white")
end