Jump to content
  • 0

Add element to the gg.choice on loop


nok1a

Question

How can i add names to the gg.choice on loop?
For each iteration it has to add a new string. When the loop is finished gg.choice has to show all the strings.

 testSetting = {}
 isUserSetting = {}
  for i, v in ipairs(isUser) do
    if isBotBool[i].value == 1 then
      isBotValue = "A.I."
    elseif isBotBool[i].value == 0 then
      isBotValue = "Human"
    end
    isUserSetting[i] = {"Nickname: "..v.name.." |User ID: "..v.value.." |Controller: "..isBotValue..""}
    testSetting[i] = {address = v.address, flags = gg.TYPE_DWORD, name = "Nickname: "..v.name.." |  Controller: "..isBotValue.." |  User ID: "..v.value}
  end
  for i, v in ipairs(isUserSetting) do
   testof = gg.choice(isUserSetting[i]) -- needs to show all user settings at once instead of one by one
  end
  gg.addListItems(testSetting)
  gg.toast("Player saved in the saved list")

If loop only has to loop twice it should look like this:

image.thumb.png.948f97c48f03687b03f1cc8dc5d5e688.png

With script provided above it will always show 1 string. Which i don't want because user will have to press through all the string results.

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

loop by using the "table.insert" function to insert a new string into the "isUserSetting" table for each iteration. After the loop is finished, "gg.choice" will display all the strings in the "isUserSetting" table.

I used the function when retrieving HexPatch strings. For example, it could be as follows.

testSetting = {}
isUserSetting = {}
for i, v in ipairs(isUser) do
  if isBotBool[i].value == 1 then
    isBotValue = "A.I."
  elseif isBotBool[i].value == 0 then
    isBotValue = "Human"
  end
  table.insert(isUserSetting, "Nickname: "..v.name.." |User ID: "..v.value.." |Controller: "..isBotValue.."")
  testSetting[i] = {address = v.address, flags = gg.TYPE_DWORD, name = "Nickname: "..v.name.." |  Controller: "..isBotValue.." |  User ID: "..v.value}
end
gg.addListItems(testSetting)
gg.choice(isUserSetting)
gg.toast("Player saved in the saved list")

 

 

 

 

 

 

Link to comment
Share on other sites

9 hours ago, Proejder said:

loop by using the "table.insert" function to insert a new string into the "isUserSetting" table for each iteration.

It seems table.insert does not support a direct string as an argument.

image.thumb.png.fa2d2cb6b9ff461cb2c91e218050dfc7.png

It works, but first had to assign a variable to the string, and then place the variable in table.insert.

local userInfo = "Nickname: "..v.name.." |User ID: "..v.value.." |Controller: "..isBotValue.."", "Nickname: "..v.name.." |User ID: "..v.value.." |Controller: "..isBotValue..""
table.insert(isUserSetting, userInfo)

image.thumb.png.45c7c40e052a3fd47b1b05f0a478d8df.png

Thanks, looks more user friendly 😉

14 hours ago, XEKEX said:

instead of the loop use : 

testof = gg.choice(table.unpack(isUserSetting))
 

I guess this should work

I tried but it gave error.

image.thumb.png.c7e719349754b82380af52acee1b614a.png

  testSetting = {}
  isUserSetting = {}
  for i, v in ipairs(isUser) do
    if isBotBool[i].value == 1 then
      isBotValue = "A.I."
    elseif isBotBool[i].value == 0 then
      isBotValue = "Human"
    end
    isUserSetting[i] = {"Nickname: "..v.name.." |User ID: "..v.value.." |Controller: "..isBotValue..""}
    testSetting[i] = {address = v.address, flags = gg.TYPE_DWORD, name = "Nickname: "..v.name.." |  Controller: "..isBotValue.." |  User ID: "..v.value}
  end
  testof = gg.choice(table.unpack(isUserSetting))

 

Link to comment
Share on other sites

Apparently this also works, i wasn't aware i can use tables like that in gg.choice. But i see it makes sense relooking the help docs.

  local testSetting = {}
  local isUserSetting = {}
  for i, v in ipairs(isUser) do
    if isBotBool[i].value == 1 then
      isBotValue = "A.I."
    elseif isBotBool[i].value == 0 then
      isBotValue = "Human"
    end
    isUserSetting[i] = "Nickname: "..v.name.." |User ID: "..v.value.." |Controller: "..isBotValue..""
    testSetting[i] = {address = v.address, flags = gg.TYPE_DWORD, name = userInfo}
  end
  testof = gg.choice(isUserSetting)
  gg.addListItems(testSetting)
  gg.toast("Player saved in the saved list")
end

 

Link to comment
Share on other sites

1 hour ago, nok1a said:

It seems table.insert does not support a direct string as an argument.

image.thumb.png.fa2d2cb6b9ff461cb2c91e218050dfc7.png

It works, but first had to assign a variable to the string, and then place the variable in table.insert.

local userInfo = "Nickname: "..v.name.." |User ID: "..v.value.." |Controller: "..isBotValue.."", "Nickname: "..v.name.." |User ID: "..v.value.." |Controller: "..isBotValue..""
table.insert(isUserSetting, userInfo)

image.thumb.png.45c7c40e052a3fd47b1b05f0a478d8df.png

Thanks, looks more user friendly 😉

I tried but it gave error.

image.thumb.png.c7e719349754b82380af52acee1b614a.png

  testSetting = {}
  isUserSetting = {}
  for i, v in ipairs(isUser) do
    if isBotBool[i].value == 1 then
      isBotValue = "A.I."
    elseif isBotBool[i].value == 0 then
      isBotValue = "Human"
    end
    isUserSetting[i] = {"Nickname: "..v.name.." |User ID: "..v.value.." |Controller: "..isBotValue..""}
    testSetting[i] = {address = v.address, flags = gg.TYPE_DWORD, name = "Nickname: "..v.name.." |  Controller: "..isBotValue.." |  User ID: "..v.value}
  end
  testof = gg.choice(table.unpack(isUserSetting))

 

Try gg.choice({table.unpack(isUserSetting}))

This should solve the issue

Link to comment
Share on other sites

Correct you had to assign the string to a variable before inserting it into the table using table.insert, and you've already done that.

Sample 

table.insert(isUserSetting, userSetting)

gg.choice(isUserSetting)

Or

15 hours ago, XEKEX said:

Try gg.choice({table.unpack(isUserSetting}))

This should solve the issue

if i define a string then it should be like

  table.insert(isUserSetting, userSetting)
  testSetting[i] = {address = v.address, flags = gg.TYPE_DWORD, name = "Nickname: "..v.name.." |  Controller: "..isBotValue.." |  User ID: "..v.value}
end
gg.choice(isUserSetting)

 

 

 

 

Link to comment
Share on other sites

instead of the loop use : 

testof = gg.choice(table.unpack(isUserSetting))
 

I guess this should work

if u put  gg.choice() inside a loop for every key it display  gg.choice() again and again and for this pop up get refreshed you need to to press cancel
in another word what it does in the loop is pause the loop wait for user to click cancel then (i+1)

and if you want this gg.choice in the loop try 
for i, v in ipairs(isUserSetting) do
if i == #isUserSetting then testof = gg.choice(isUserSetting[i]) break; end -- to avoid the testof = nil
testof = gg.choice(isUserSetting[i]) 
sleep(500)
testof = nil
end

Link to comment
Share on other sites

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.