Jump to content
  • 0

Help with seekbar gg.prompt add variable group search


Kimiice7

Question

Please help me how to make group search like this

r = gg.prompt({'LEVEL [1;5]'},{1},{'number'})
p = {'10','20','30','40','50'}


--bad list--
if r[1] == '1' then rp = p[1] end
if r[1] == '2' then rp = p[2] end
if r[1] == '3' then rp = p[3] end
if r[1] == '4' then rp = p[4] end
if r[1] == '5' then rp = p[5] end

gg.searchNumber(r[1]..';100;'..rp..';1000:', gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1)

--How to call rp in group search without making bad list..??--
--Because i have 100 items in table p{} --
-- for p[x] , how to set x= r[1] ?? --
-- i tried this --
--gg.searchNumber(r[1]..';100;'..p[r[1]]..';1000:', gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1)--
--also tried x = r[1] then call p[x] but didn't work--

--Thanks for your help guys--

help variable gg.prompt.lua

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

On 12/5/2019 at 3:47 PM, Kimiice7 said:

Please help me how to make group search like this

r = gg.prompt({'LEVEL [1;5]'},{1},{'number'})
p = {'10','20','30','40','50'}


--bad list--
if r[1] == '1' then rp = p[1] end
if r[1] == '2' then rp = p[2] end
if r[1] == '3' then rp = p[3] end
if r[1] == '4' then rp = p[4] end
if r[1] == '5' then rp = p[5] end

gg.searchNumber(r[1]..';100;'..rp..';1000:', gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1)

--How to call rp in group search without making bad list..??--
--Because i have 100 items in table p{} --
-- for p[x] , how to set x= r[1] ?? --
-- i tried this --
--gg.searchNumber(r[1]..';100;'..p[r[1]]..';1000:', gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1)--
--also tried x = r[1] then call p[x] but didn't work--

--Thanks for your help guys--

help variable gg.prompt.lua 720 B · 3 downloads

well , if you need to do this om exactly this numbers then use it : ) :

local r = gg.prompt({'LEVEL [1;5]'},{1},{'number'})

local rp = r[1]*10

gg.searchNumber(r[1]..';100;'..rp..';1000:', gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1)

Link to comment
Share on other sites

11 minutes ago, Kimiice7 said:

-- i tried this --
--gg.searchNumber(r[1]..';100;'..p[r[1]]..';1000:', gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1)--

This approach is correct, but there is one detail that is not considered: string that represents a number and an actual number is not the same key in a table. For example, r[1] and r['1'] refer to two different values in the table.

So if you have string that represents a number, just convert it to an actual number using "tonumber" function (or any other way), then use that number to index the table with values for group search (table "p" in your case). Something like this: 

gg.searchNumber(r[1]..';100;'..p[tonumber(r[1])]..';1000:', gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1)

And that's it, you don't need bad list anymore. Also don't forget that "prompt" function can return nil and this case should be handled in order to avoid errors.

Link to comment
Share on other sites

 There are three ways to solve.
First two required you to create a table. 

First method

local num = {
{value = 1, number = "10"},
{value = 2, number = "20"},
{value = 3, number = "30"},
{value = 4, number = "40"},
{value = 5, number = "50"}}

With this table, you can do checking and do number searching. 
 

for _, v in ipairs(num) do
    if v.value == r[1] then
		gg.searchNumber(r[1]..';100;'..v.number..';1000:', 4)
        
    end
end

 

Second method:

 

local num = {
[1] = "10",
[2] = "20",
[3] = "30",
[4] = "40",
[5] = "50"}

gg.searchNumber(r[1]..';100;'..num[r[1]]..';1000:', 4)

Third method : 

Since you have a sequence of x * 10. 
then simply do this.

gg.searchNumber(r[1]..';100;'..(r[1]*10)..';1000:', 4)

 

Link to comment
Share on other sites

18 minutes ago, CmP said:

This approach is correct, but there is one detail that is not considered: string that represents a number and an actual number is not the same key in a table. For example, r[1] and r['1'] refer to two different values in the table.

So if you have string that represents a number, just convert it to an actual number using "tonumber" function (or any other way), then use that number to index the table with values for group search (table "p" in your case). Something like this: 


gg.searchNumber(r[1]..';100;'..p[tonumber(r[1])]..';1000:', gg.TYPE_DWORD, false, gg.SIGN_EQUAL, 0, -1)

And that's it, you don't need bad list anymore. Also don't forget that "prompt" function can return nil and this case should be handled in order to avoid errors.

Thanks man..

This is exactly what i want to do but i don't know how to make it..

You gave me a simple and clear explaination..

And the example make it perfect..

Thanks alot..

Really appreciate..

[sorry have bad english]

Link to comment
Share on other sites

35 minutes ago, ItsSC said:

 There are three ways to solve.
First two required you to create a table. 

First method


local num = {
{value = 1, number = "10"},
{value = 2, number = "20"},
{value = 3, number = "30"},
{value = 4, number = "40"},
{value = 5, number = "50"}}

With this table, you can do checking and do number searching. 
 


for _, v in ipairs(num) do
    if v.value == r[1] then
		gg.searchNumber(r[1]..';100;'..v.number..';1000:', 4)
        
    end
end

 

Second method:

 


local num = {
[1] = "10",
[2] = "20",
[3] = "30",
[4] = "40",
[5] = "50"}

gg.searchNumber(r[1]..';100;'..num[r[1]]..';1000:', 4)

Third method : 

Since you have a sequence of x * 10. 
then simply do this.


gg.searchNumber(r[1]..';100;'..(r[1]*10)..';1000:', 4)

 

I can't use third methode.. Because the real table i have they not contain the squennced numbers like 10,20,30

Anyway..

Thanks for show me some defferent methode..

Its usefull to improve my kowledge and my skill..

Thanks bro.. Appreciate this..

 

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.