Jump to content
  • 0

User input Value search error


Ardit19
 Share

Question

I have created a code that search and edits values depending on user inputs, but when it comes in executing it gg says that the search value is nil, even though inputs are not empty.

 

Error:

gg.searchNumber(nBV[num2], gg.TYPE_DWORD)

bad argument #1: nil: string expected, got nil (field 'searchNumber')

local nBV = { 
   [1248889551] = 2000,
   [1248889552] = 4000,
   [1248889553] = 6000,
   [1248889554] = 8000,
   [1248889555] = 10000 }
local PromptN = gg.prompt({[2] = 'Type Gold Storage Capacity Right Now', [1] = 'Type Ideal Gold Storage Capacity [ 2000 ~ 10000 ]'}, {[2] = 2000, [1] = 10000},  {[2] = 'number', [1] = 'number'})
if PromptN[1] == nil or PromptN[1] == '' or PromptN[2] == nil or PromptN[2] == '' then
    gg.toast('Canceling, Please Type Values!')
else
    local num1 = PromptN[1]
    local num2 = PromptN[2]
    gg.clearResults()
    gg.clearList()
    gg.searchNumber(nBV[num2], gg.TYPE_DWORD)
    gg.getResults(gg.getResultsCount())
    gg.editAll(nBV[num1], gg.TYPE_DWORD)
    gg.clearList()
    gg.clearResults()
end

Any help would be appreciated!

Edited by Ardit19
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

a simple solution without the local table nBV will be look like this :

local PromptN = gg.prompt({[2] = 'Type Gold Storage Capacity Right Now', [1] = 'Type Ideal Gold Storage Capacity [ 2000 ~ 10000 ]'}, {[2] = 2000, [1] = 10000},  {[2] = 'number', [1] = 'number'})
if PromptN[1] == nil or PromptN[1] == '' or PromptN[2] == nil or PromptN[2] == '' then
    gg.toast('Canceling, Please Type Values!')
else
    local num1 = PromptN[1]
    local num2 = PromptN[2]
    gg.clearResults()
    gg.clearList()
    gg.searchNumber(num2, gg.TYPE_DWORD)
    gg.getResults(gg.getResultsCount())
    gg.editAll(num1, gg.TYPE_DWORD)
    gg.clearList()
    gg.clearResults()
end

but if the table is somehow super important then i'll let the expert fix it.

Edited by MonkeySAN
Link to comment
Share on other sites

  • 0
3 hours ago, MonkeySAN said:

a simple solution without the local table nBV will be look like this :

local PromptN = gg.prompt({[2] = 'Type Gold Storage Capacity Right Now', [1] = 'Type Ideal Gold Storage Capacity [ 2000 ~ 10000 ]'}, {[2] = 2000, [1] = 10000},  {[2] = 'number', [1] = 'number'})
if PromptN[1] == nil or PromptN[1] == '' or PromptN[2] == nil or PromptN[2] == '' then
    gg.toast('Canceling, Please Type Values!')
else
    local num1 = PromptN[1]
    local num2 = PromptN[2]
    gg.clearResults()
    gg.clearList()
    gg.searchNumber(num2, gg.TYPE_DWORD)
    gg.getResults(gg.getResultsCount())
    gg.editAll(num1, gg.TYPE_DWORD)
    gg.clearList()
    gg.clearResults()
end

but if the table is somehow super important then i'll let the expert fix it.

Here me out if Prompt[2] is 2000 for example then to search 1248889551 and if Prompt[1] is 10000 to edit with 1248889555. I don't know if it's clear, but that's how I want it to work

Link to comment
Share on other sites

  • 0

maybe this will work?

local nBV = {
    [1248889551] = 2000,
    [1248889552] = 4000,
    [1248889553] = 6000,
    [1248889554] = 8000,
    [1248889555] = 10000}
    

local PromptN = gg.prompt({[2] = 'Enter Current Gold Storage Capacity :', [1] = 'Enter Ideal Gold Storage Capacity : [2000 ~ 10000]'}, {[2] = 2000, [1] = 10000},  {[2] = 'number', [1] = 'number'})

if not PromptN or  PromptN[1] == "" or PromptN[2] == "" then gg.toast('Canceling, Please Enter a Value!')
else
    local num1 = PromptN[1]
    local num2 = PromptN[2]
    gg.clearResults()
    gg.clearList()
    
    -- Find the key corresponding to the user input value
    local targetKey
    local editKey
    for k, v in pairs(nBV) do
        if v == tonumber(num2) then
            targetKey = k
        elseif 
            v == tonumber(num1) then
            editKey = k
        end
    end
    
    -- Search and replace the current value with the target value
if targetKey and editKey then
    gg.alert("Search value = "..targetKey.."\nEdit with = "..editKey)
gg.searchNumber(targetKey, gg.TYPE_DWORD)
local result = gg.getResults(gg.getResultsCount())
if #result == 0 then gg.alert("Values not found") os.exit() end
    gg.editAll(editKey, gg.TYPE_DWORD)
else
    gg.toast('Value not found in the table!')
end
    gg.clearList()
    gg.clearResults()
end

 

Edited by MonkeySAN
Link to comment
Share on other sites

  • 0
19 hours ago, MonkeySAN said:

maybe this will work?

local nBV = {
    [1248889551] = 2000,
    [1248889552] = 4000,
    [1248889553] = 6000,
    [1248889554] = 8000,
    [1248889555] = 10000}
    

local PromptN = gg.prompt({[2] = 'Enter Current Gold Storage Capacity :', [1] = 'Enter Ideal Gold Storage Capacity : [2000 ~ 10000]'}, {[2] = 2000, [1] = 10000},  {[2] = 'number', [1] = 'number'})

if not PromptN or  PromptN[1] == "" or PromptN[2] == "" then gg.toast('Canceling, Please Enter a Value!')
else
    local num1 = PromptN[1]
    local num2 = PromptN[2]
    gg.clearResults()
    gg.clearList()
    
    -- Find the key corresponding to the user input value
    local targetKey
    local editKey
    for k, v in pairs(nBV) do
        if v == tonumber(num2) then
            targetKey = k
        elseif 
            v == tonumber(num1) then
            editKey = k
        end
    end
    
    -- Search and replace the current value with the target value
if targetKey and editKey then
    gg.alert("Search value = "..targetKey.."\nEdit with = "..editKey)
gg.searchNumber(targetKey, gg.TYPE_DWORD)
local result = gg.getResults(gg.getResultsCount())
if #result == 0 then gg.alert("Values not found") os.exit() end
    gg.editAll(editKey, gg.TYPE_DWORD)
else
    gg.toast('Value not found in the table!')
end
    gg.clearList()
    gg.clearResults()
end

 

Works like a charm! Thanks a lot! I appreciate it

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.