Discord
Login
Community
DARK THEME

How does the prompt function work

im trying to use networking to make a multiplayer texting thing (mainly to test my skills) and I can’t get the system.prompt thing to work (It’s mainly because I can’t get the callback thing to work right) any ideas on how to fix this

For callback you use the function as an arguement here's an example if mouse.pressed then // Call system.prompt with a callback function system.prompt("Please enter your name:", function(ok, text) if ok then userName = text else userName = "User cancelled prompt" end end) end

So the function is defined elsewhere correct?

no the function is defined inside as seen in function(ok, text) if ok then userName = text else userName = "User cancelled prompt" end end) this is the actual function while it is possible to define the function somewhere else I am used to doing it this way

To simply explain it, the callback function has to be defined by yourself.

While it is used like a variable when you use it (as seen in system.prompt(text, callback) for example), you define it as a function.

You can either do this separate, or directly integrated into the prompt function, as AJ mentioned above.

The parameter ok is a boolean, that will check if the user proceeded, or canceled the Prompt. text is what the user inputted.

Here you can see it as a separate function:

callback = function(ok, text)
  if ok then
    print(text)
  end
end

system.prompt("Enter something!", callback)

And here you can see it together:

system.prompt("Enter!", function(ok, text) print(text) end)

So could I set a variable to text instead of printing it

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community