Jump to content

Question

Posted

I used to script a little back in the day and I am trying to get back into it. 
 

I have a script that searches for value in this case 1048 (which is dirt In this game) then it uses gg.editAll to change the diet value into any other block. 
 

what I am having trouble with is I want to make a system where the user of the script can type what they want that 1048 value to turn into to. As in they could type stone and the script would search through a list for stone and find a paired integer corresponding to stone. Then it uses the stones integer to gg.editAll of the dirt (1048) into the stone. 
 

all I am having trouble with is the list part

I have some knowledge of python and it would be pretty easy to do in python is their a similar way to do it in gg code?

3 answers to this question

Recommended Posts

  • 3
Posted (edited)

How to store that data in your code effectively depends on which interface to choose an item script needs to provide. If user input is name of item, then table item names as keys and item identifiers as values can work well. If user chooses option from list of possible items, then it can be table of tables with each inner table having name and value fields. Below is an example of tables for both of mentioned options: 

-- Option 1
local items = {
  ["dirt"] = 123,
  ["stone"] = 456
}
-- Option 2
local items = {
  {name = "dirt", value = 123},
  {name = "stone", value = 456}
}
Edited by CmP
  • 0
Posted (edited)
 
On 1/26/2025 at 4:15 AM, TheBlockheads said:

I used to script a little back in the day and I am trying to get back into it. 
 

I have a script that searches for value in this case 1048 (which is dirt In this game) then it uses gg.editAll to change the diet value into any other block. 
 

what I am having trouble with is I want to make a system where the user of the script can type what they want that 1048 value to turn into to. As in they could type stone and the script would search through a list for stone and find a paired integer corresponding to stone. Then it uses the stones integer to gg.editAll of the dirt (1048) into the stone. 
 

all I am having trouble with is the list part

I have some knowledge of python and it would be pretty easy to do in python is their a similar way to do it in gg code?

Yes, you can create a dictionary (table) in Lua to pair block names with their corresponding values. Then, use gg.prompt() to let the user input a block name, check if it exists in the table, and retrieve the corresponding integer. Here's an example of how you can implement it in GG Lua:

 

local blocks = {
    ["dirt"] = 1048,
    ["stone"] = 1050,
    ["sand"] = 1062,
    -- Add more block names and their values here
}
local input = gg.prompt({"Enter block name:"}, {}, {"text"})
if input and input[1] then
    local targetValue = blocks[input[1]:lower()]
    if targetValue then
        gg.searchNumber("1048", gg.TYPE_DWORD)
        gg.editAll(targetValue, gg.TYPE_DWORD)
        gg.toast("Changed dirt to " .. input[1])
    else
        gg.alert("Block name not found in the list!")
    end
end

This allows users to input a block name, look it up in the table, and replace the original value with the correct integer. Just make sure to expand the blocks table with all necessary block types. Hope this helps!

Edited by JastardNeverdie
  • 0
Posted
On 3/14/2025 at 10:30 AM, JastardNeverdie said:
 

Yes, you can create a dictionary (table) in Lua to pair block names with their corresponding values. Then, use gg.prompt() to let the user input a block name, check if it exists in the table, and retrieve the corresponding integer. Here's an example of how you can implement it in GG Lua:

 

local blocks = {
    ["dirt"] = 1048,
    ["stone"] = 1050,
    ["sand"] = 1062,
    -- Add more block names and their values here
}
local input = gg.prompt({"Enter block name:"}, {}, {"text"})
if input and input[1] then
    local targetValue = blocks[input[1]:lower()]
    if targetValue then
        gg.searchNumber("1048", gg.TYPE_DWORD)
        gg.editAll(targetValue, gg.TYPE_DWORD)
        gg.toast("Changed dirt to " .. input[1])
    else
        gg.alert("Block name not found in the list!")
    end
end

This allows users to input a block name, look it up in the table, and replace the original value with the correct integer. Just make sure to expand the blocks table with all necessary block types. Hope this helps!

🤌🏻👏🏻👏🏻 But requester not see yet 🤦🏻‍♂️ 

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