chatGPT writes a script

chatGPT writes a script

joep_swagemakers
Enthusiast Enthusiast
3,587 Views
6 Replies
Message 1 of 7

chatGPT writes a script

joep_swagemakers
Enthusiast
Enthusiast

Hello,

 

I'm not a coder at all so I never got into MAXscript. But now that chatGPT can write code for you this is becoming very interesting to me. I've been experimenting with some things I want chatGPT to write for me and it looks great but there are small errors in the code which I cannot fix because I'm not a coder. 

 

Do you guys have experience with chatGPT writing code for you and how did you solve the potential errors? 

 

This is the code chatGPT wrote for me:

 

 

 

-- Create a window for the script
window = newRolloutFloater "Cube Grid Generator" 200 200

-- Create a rollout for the script
rollout = newRollout "Cube Grid Generator" window

-- Create a button to generate the cubes
generateButton = button rollout "Generate Cubes"

-- Create a button to set the spacing
spacingButton = button rollout "Set Spacing"

-- Create a button to open the material editor
materialButton = button rollout "Add Material"

-- Create variables for cube size, grid size, and spacing
global cubeSize = 10
global gridSize = 26
global spacing = 1

-- Create a function to generate the cubes
fn generateCubes =
(
    -- Create an array of cubes
    cubes = #()

    -- Create the grid of cubes
    for i = 0 to gridSize-1 do
    (
        for j = 0 to gridSize-1 do
        (
            -- Create a new cube
            newCube = box()

            -- Position the cube in the grid
            newCube.pos.x = (i * (cubeSize + spacing)) + (spacing / 2)
            newCube.pos.z = (j * (cubeSize + spacing)) + (spacing / 2)

            -- Add the cube to the array
            append cubes newCube
        )
    )
    -- Create a new plane
    newPlane = plane()

    -- Scale the plane to the same size as the grid
    newPlane.scale = [gridSize*(cubeSize+spacing),1,gridSize*(cubeSize+spacing)]

    -- Position the plane on top of the cubes
    newPlane.pos.y = (cubeSize + spacing) / 2
)

-- Create a function to set the spacing
fn setSpacing =
(
    -- Get the new spacing value from the user
    spacing = inputBox "Enter the spacing (in cm):" "Spacing"
    -- Convert the spacing to a float
    spacing = spacing as float
)

-- Create a function to open the material editor and assign a selected material to the plane
fn addMaterial =
(
    -- Open the material editor
    openMaterialEditor()

    -- Assign the selected material to the plane
    newPlane.material = getCurrentMaterial()
)

-- Add the functions to the buttons
on generateButton pressed do generateCubes()
on spacingButton pressed do setSpacing()
on materialButton pressed do addMaterial()

-- Add the buttons to the rollout
add generateButton rollout
add spacingButton rollout
add materialButton rollout

-- Add the rollout to the window
addRollout rollout window

 

 

 

So the first error you get is that rollout cannot be a variable name. I changed that but it still doesn't work. 

 

-Joep

0 Likes
3,588 Views
6 Replies
Replies (6)
Message 2 of 7

Serejah
Advocate
Advocate

This is miles away from the correct maxscript syntax. Don't waste your time. If neither chatGPT nor yourself don't know the correct syntax for the simplest things how are you going to debug it or ask chatGPT to fix the error... too time consuming, imo.

0 Likes
Message 3 of 7

Swordslayer
Advisor
Advisor

@joep_swagemakers wrote:

there are small errors in the code which I cannot fix because I'm not a coder 


There's more errors, made up convenient function names and made up syntax than working code...

 

@joep_swagemakers wrote:

Do you guys have experience with chatGPT writing code for you and how did you solve the potential errors? 


I have experience in explaining others how it's much easier to write it from scratch rather than trying to start from a botched non-working something generated by ChatGP. It works well(-ish) for stuff that's often used in homework assignments of popular languages (but even then, you're usually better off googling, and less at risk of encountering weird random bugs introduced by ChatGP). For maxscript, the only use I can think of is to get better prompts to find stuff on google, or for writing nice post asking for help. 

Message 4 of 7

istan
Advisor
Advisor

I am surprised that even "any" MXS code falls out of it..

0 Likes
Message 5 of 7

Serejah
Advocate
Advocate

Wonder if github copilot can do any better. Most likely is it as bad as chatgpt since maxscript code base is terribly small compared to popular programming languages

0 Likes
Message 6 of 7

joep_swagemakers
Enthusiast
Enthusiast

Ah oke, well I didn't have a clue about how useable this script is. For now chatGPT remains unuseable for the most part, small scripts still work though. Let's give it a bit more time and see if things improve. For me this would be VERY useful! Eventually it will get good enough to write scripts for you, no doubt about it, it just needs time and I guess more data on MXS.

0 Likes
Message 7 of 7

denisT.MaxDoctor
Advisor
Advisor

@joep_swagemakers wrote:

... it just needs time and I guess more data on MXS.


two or three years is nothing... me and my client are willing to wait.

0 Likes