Jump to content
  • 0

Call Function() using gg.prompt


1x1
 Share

Question

I wanna make a gg.prompt which can do main() or any function.

 

Here is 1 example I made but it doesn't work with gg.prompt

 

function test1()
  gg.alert('Test1 ok')
 end

function abc()
  gg.alert('no bye')
  os.exit()
  end

local response = gg.prompt({'Put function to call'}, {''}, {'text'})

pcall(load(response[1]))

but it doesn't work. When I put it function name instead of response[1] it work.

 

I'm trying to make a database. 

Link to comment
Share on other sites

1 answer to this question

Recommended Posts

  • 0

function test_1()
  gg.alert('Test1 ok')
 end
function test_2()
  gg.alert('no bye')
  os.exit()
  end



local response = gg.prompt({'function test','function test 2'}, {'',''}, {'text','text'})

if response ~= nil then
  if response[1] then test_1() 
  elseif response[2] then test_2()
  end
end

 you can also do
 

func = {
[1] = function()
  gg.alert('Test1 ok')
 end,
[2] = function()
  gg.alert('no bye')
  os.exit()
  end,
...
}



local response = gg.prompt({'function test','function test 2'}, {'',''}, {'text','text'})

if response ~= nil then -- check if the user input somthing
  for k,v in pairs(response) do --iterate over the response table and check where the user input ( check the index )
	if v~= '' then func[k]() end -- check the value of each index isn't nil then we call the function correspond to that index from func table
  end
end



--[[ Note:
func index must be the same index as response ( make sure you put the same order )

 

Edited by XEKEX
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • 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.