Jump to content

How to convert error message to string?


Cornysz

Recommended Posts

Posted

Is it possible to convert error message to string? Example my script have prompt and i input random number and then i got error, and i want after that the script will automatically alert the error.

  • Administrators
Posted

Read data, check contents. If it is not fit you - show alert. You can try use tonumber or regular expression, whatever.

Posted
Read data, check contents. If it is not fit you - show alert. You can try use tonumber or regular expression, whatever.
What do u mean of Read data, check contents i dont have idea to make dat oof
  • Administrators
Posted

You receive some input from the user. This will be your data. Before you use them, check that there is what you need, and not just random nonsense.

Posted
4 hours ago, Cornysz said:

What do u mean of Read data, check contents i dont have idea to make dat oof

local min = 4
local max = 10
local data = gg.prompt({'Input a number between ' .. min .. ' and ' .. max}, {min}, {'number'}) -- read data
-- Check contents
if data == nil then
  gg.alert('Dialog was cancelled')
  os.exit()
end
local number = tonumber(data[1])
if number == nil then
  gg.alert('Input was not a valid number')
  os.exit()
end
if number < min or number > max then -- if does not fit
  gg.alert('Input number is not within allowable range') -- show alert
  os.exit() -- and interrupt script execution (or do whatever is required)
end

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.