ChatGPT writes Lua code for Solar2D!!!

This is a game changer. Has anyone else used ChatGPT to write code in Lua for Solar2D? If so, please post some here. Here’s a brief test I gave it.

TROY: Can you write me some code in Lua with the Solar2D sdk to display a circle and then move that circle from the upper left to the bottom right in 2 seconds?

CHATGPT: Certainly! Here’s some code in Lua with the Solar2D SDK that creates a circle, positions it in the upper-left corner of the screen, and moves it to the bottom-right corner over a period of 2 seconds:

local circle = display.newCircle(50, 50, 25) -- create a new circle at position (50, 50) with a radius of 25
circle:setFillColor(1, 0, 0) -- set the circle's fill color to red

transition.to(circle, { x = display.contentWidth - 50, y = display.contentHeight - 50, time = 2000 }) -- move the circle to position (width - 50, height - 50) over a period of 2 seconds

CHATGPT (explanation): In this code, the display.newCircle() function creates a new circle object with a position of (50, 50) and a radius of 25. The setFillColor() function sets the circle’s fill color to red.

The transition.to() function then moves the circle to the position (width - 50, height - 50), which is the bottom-right corner of the screen, over a period of 2 seconds. The time parameter specifies the duration of the transition in milliseconds.

I hope this helps! Let me know if you have any questions.

I haven’t tried it with Solar2D yet, at the moment I’m playing with the Lapis web framework, but I created a lua code in ChatGPT so that in Lapis I could get a function to generate a random 6-digit password, which would not be repeated and only with the characters ABCDEFGH0123456789

Some of us in the Solar2D Discord server have been poking at it since last December… a lot has happened since then. :grinning_face_with_smiling_eyes:

1 Like

Has anyone actually gotten any usable work out of it yet, or is it still at the novelty / proof-of-concept stage?

I will be writing some kind of solitaire game later in the year; that’s when I plan to try having ChatGTP write parts of it; if it works well, I’ll post details here. :slight_smile:

Oh, it’s definitely past the novelty stage. At first I thought it was a glorified search engine, but it has really surpassed its hype.

In general, it has replaced my Google search time by about 90%.

As far as coding goes, it has helped me solved issues in matter of minutes where I had spent hours trying to figure it out.

It’s great for code snippets, and can handle creating modules if you start out with a basic, short or detailed input, and gradually expand on it.

I’ve used it for Lua, HTML, Javascript, and C++, in the context of Solar2D and other libraries.

1 Like

it writes fairly amateur unoptimized code from what I can see but it does the job on a basic level. it is far from production code yet though.

I think ChatGPT can be a great planning tool. I asked it this.

TROY: Can you create a logic flow-chart for me in OneNote?

CHATGPT: Yes, I can create a logic flow-chart for you in OneNote. Please provide me with the specifications and details for the flow-chart, such as the specific actions, conditions, and desired output that you would like included. Additionally, please let me know if you have any preferences for the design or layout of the flow-chart, such as color schemes or font styles.

Tried using it to get a template for shooting events at Unity Analytics using their Open API. The code was obviously syntactically sound but wasn’t in line with Unity’s latest guidelines for the API and didn’t work.

Also tried getting it to generate a particle emitter for fire+smoke which wasn’t too bad. Colours etc were off but the boring bits of populating all the parameters and tables etc were taken care of so I could always paste it into my programme and edit it how I want

1 Like

I’ve tried it with Solar to visualize a prototype we were working on and it works fine but definitely needed some fine tuning. It saved me some time though. Haven’t tried it yet with GPT-4 but I guess it’d be far better.

1 Like

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.