Jump to content
  • 0

refine value with multiChoice


XkPP
 Share

Question

tar = gg.getResults(gg.getResultCount())
val = {}
for i, v in ipairs(tar) do
table.insert(val,v.value)
end


local menu = gg.multiChoice(val,nil,"")
if not menu then os.exit() end
if menu[val] == true then
gg.refineNumber(menu[val],4)
end

 

when I try it doesn't respond to refine please help

Link to comment
Share on other sites

10 answers to this question

Recommended Posts

  • 0
Posted (edited)
On 6/28/2022 at 6:02 AM, XkPP said:

tar = gg.getResults(gg.getResultCount())
val = {}
for i, v in ipairs(tar) do
table.insert(val,v.value)
end


local menu = gg.multiChoice(val,nil,"")
if not menu then os.exit() end
if menu[val] == true then
gg.refineNumber(menu[val],4)
end

 

when I try it doesn't respond to refine please help

It's not menu[val]. If your multichoice gets val, and val is a table, then gg will return the index checkbox you selected.

Fixed:

local menu = gg.multiChoice(val,nil,"")
if menu == nil then
os.exit() -- user clicked 'cancel'
end
local index = 0
while menu[index] ~= true do
index = index + 1
if index > #menu then
os.exit() - no checkboxes selected
end
end
gg.refineNumber(val[index],4)
end

Another way to do this is with gg.choice. gg.choice has different ui (only lets you select one, rather than checkboxes) and returns the index of the one you clicked.

local menu = gg.choice(val,nil,"")
if menu == nil then
os.exit() -- user clicked 'cancel'
end
gg.refineNumber(val[menu],4)
end

 

Edited by HorridModz
fixed mistake
Link to comment
Share on other sites

  • 0
Posted (edited)
On 7/4/2022 at 6:32 AM, HorridModz said:
local menu = gg.multiChoice(val,nil,"")
if menu == nil then
os.exit() -- user clicked 'cancel'
end
local index = 0
while menu[index] ~= true do
if index > #menu then
os.exit() - no checkboxes selected
end
end
gg.refineNumber(val[index],4)
end

after I tried it with one of the values the loading took a long time, can you fixed it again?

Edited by XkPP
Link to comment
Share on other sites

  • 0
On 7/6/2022 at 6:50 AM, XkPP said:

after I tried it with one of the values the loading took a long time, can you fixed it again?

I don't know what you mean. I also don't intend to fix any issues you have.
I'm trying to explain to you how to do what you want to do. It's great that you want to make a script using advanced features and I know it's not easy. But I'm not going to make your script for you. I'm only here to help you when you get stuck on how to do something.

Please rephrase what you mean by this - I don't get what you are trying to say.

Link to comment
Share on other sites

  • 0
Posted (edited)

@HorridModz

16 hours ago, HorridModz said:

Please rephrase what you mean by this - I don't get what you are trying to say.

This is the video I meant, it took a long time to load

 

sorry if the video quality is not good

Edited by XkPP
Link to comment
Share on other sites

  • 0
5 hours ago, XkPP said:

@HorridModz

This is the video I meant, it took a long time to load

 

sorry if the video quality is not good

Ugh, this is exactly what I said.

I just made a mistake in that code. Use this new code.

On 7/3/2022 at 7:32 PM, HorridModz said:
local menu = gg.multiChoice(val,nil,"")
if menu == nil then
os.exit() -- user clicked 'cancel'
end
local index = 0
while menu[index] ~= true do
index = index +1
if index > #menu then
os.exit() - no checkboxes selected
end
end
gg.refineNumber(val[index],4)
end

 

 

Just now, HorridModz said:

Ugh, this is exactly what I said.

I just made a mistake in that code. Use this new code.

Try the code in the quote.

I updated it.

Link to comment
Share on other sites

  • 0
Posted (edited)
14 hours ago, HorridModz said:

I just made a mistake in that code. Use this new code

@HorridModz pretty good no error but this only works for 1 option (like gg.choice), for example using gg.alert and select 2-4 values but gg.alert only responds to 1 value above it and does not respond to other values that are selected, can it be improved again?  because I want to try to put the selected value more than 1 into the list item

Edited by XkPP
Link to comment
Share on other sites

  • 0
Posted (edited)
4 hours ago, XkPP said:

@HorridModz pretty good no error but this only works for 1 option (like gg.choice), for example using gg.alert and select 2-4 values but gg.alert only responds to 1 value above it and does not respond to other values that are selected, can it be improved again?  because I want to try to put the selected value more than 1 into the list item

local menu = gg.multiChoice(val,nil,"")
if menu == nil then
os.exit() -- user clicked 'cancel'
end
local index = 0
while menu[index] ~= true do
index = index + 1
if index > #menu then
os.exit() -- no checkboxes selected
end
end
for i,v in pairs(menu) do
print(val[index]) --test with print
end

I have changed this, it works but there is still an error when selecting the selected value only responds to the above and the rest the values do not match but follow the top one selected first, can you change this which I have changed a bit?

Edited by XkPP
Link to comment
Share on other sites

  • 0

Ah ok. Here's code for that:

The code may have some errors.

It works by building an array of all the values you selected, and removing any results that do not have any of those values.

local function contains(item,array)
  	local index
  	local value
    for index, value in ipairs(array) do
       	if value == item then
            return true
        end
    end

    return false
end

local menu = gg.multiChoice(val,nil,"") 
if menu == nil then 
os.exit() -- user clicked 'cancel' 
end 
valid = {}
local index = 0
while index < #menu do
index = index + 1
if menu[index] then
valid[#valid + 1] = val[index]
end 
end
results = gg.getResults(gg.getResultsCount())
for result in results do
if not(contains(result.value,results)) then
gg.removeResults(result)
end
end

 

Link to comment
Share on other sites

  • 0
On 7/21/2022 at 9:41 AM, Lover1500 said:

I am not sure if this is what you need. I add some instruction that I think it is easy to understand.

refiningValues.lua 1.23 kB · 2 downloads

Thanks for helping! My code does the same thing, but now @XkPPhas options! They can choose whichever one they understand the most.

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.