ChatGPT Hollywood code
Posted: Tue Feb 07, 2023 10:43 am
Not so surprisningly, ChatGPT / OpenAI is not yet quite able to create fully functiuonal Hollywood code.
I asked it first to create the Hello World code, but every commandline was wrong. It does have a learning function, but even after correcting it and suggested a workinging example (twice), it still insisted in providing that wrong code.
Then I asked it to provide the code for a simple Pong game and this is what I got
Next, I did work through the code and tried to make a working code out of it while changing as little as possible
I have commented the non-working lines and created the working code below each line
The example above is the result I got a couple of days ago. I do not remember the exact question I asked to get the reply about, but when I tried today to replicate the question it gave me a different code that I suspcet was much closer to the C language.
I asked it first to create the Hello World code, but every commandline was wrong. It does have a learning function, but even after correcting it and suggested a workinging example (twice), it still insisted in providing that wrong code.
Then I asked it to provide the code for a simple Pong game and this is what I got
Code: Select all
; Pong game in Hollywood
; Set up the window
OpenWindow(0, 0, 300, 200, "Pong", #PB_Window_SystemMenu)
; Variables for ball position and velocity
BallX = 150 : BallY = 100
BallVX = 2 : BallVY = 2
; Variables for paddle positions
Paddle1Y = 75 : Paddle2Y = 75
; Main game loop
Repeat
; Clear the screen
ClearScreen()
; Move the ball
BallX = BallX + BallVX
BallY = BallY + BallVY
; Bounce the ball off the top and bottom walls
If BallY < 0 Or BallY > 190
BallVY = -BallVY
EndIf
; Check for paddle collisions
If BallX < 20 And BallY > Paddle1Y And BallY < Paddle1Y + 50
BallVX = -BallVX
EndIf
If BallX > 280 And BallY > Paddle2Y And BallY < Paddle2Y + 50
BallVX = -BallVX
EndIf
; Check for scoring
If BallX < 0
MessageRequester("Player 2 wins!", "Score")
BallX = 150 : BallY = 100
EndIf
If BallX > 300
MessageRequester("Player 1 wins!", "Score")
BallX = 150 : BallY = 100
EndIf
; Draw the ball
DrawCircle(BallX, BallY, 5, #PB_Pixel_Red)
; Draw the paddles
DrawRectangle(10, Paddle1Y, 10, 50, #PB_Pixel_White)
DrawRectangle(280, Paddle2Y, 10, 50, #PB_Pixel_White)
; Move the paddles with the mouse
Paddle1Y = MouseY() - 25
Paddle2Y = BallY - 25
; Update the screen
UpdateWindow()
ForeverI have commented the non-working lines and created the working code below each line
Code: Select all
; Pong game in Hollywood
; Set up the window
;OpenWindow(0, 0, 300, 200, "Pong", #PB_Window_SystemMenu)
@DISPLAY{Y = 0, X = 0, WIDTH=300,HEIGHT=200, Title = "PONG"}
; Variables for ball position and velocity
;BallX = 150 : BallY = 100
BallX = 150
BallY = 100
;BallVX = 2 : BallVY = 2
BallVX = 2
BallVY = 2
; Variables for paddle positions
;Paddle1Y = 75 : Paddle2Y = 75
Paddle1Y = 75
Paddle2Y = 75
; Main game loop
Repeat
; Clear the screen
;ClearScreen()
Cls
; Move the ball
BallX = BallX + BallVX
BallY = BallY + BallVY
; Bounce the ball off the top and bottom walls
If BallY < 0 Or BallY > 190
BallVY = -BallVY
EndIf
; Check for paddle collisions
If BallX < 20 And BallY > Paddle1Y And BallY < Paddle1Y + 50
BallVX = -BallVX
EndIf
If BallX > 280 And BallY > Paddle2Y And BallY < Paddle2Y + 50
BallVX = -BallVX
EndIf
; Check for scoring
If BallX < 0
;MessageRequester("Player 2 wins!", "Score")
SystemRequest("Player 2 wins!", "Score", "OK")
;BallX = 150 : BallY = 100
BallX = 150
BallY = 100
EndIf
If BallX > 300
;MessageRequester("Player 1 wins!", "Score")
SystemRequest("Player 1 wins!", "Score", "OK")
;BallX = 150 : BallY = 100
BallX = 150
BallY = 100
EndIf
; Draw the ball
;DrawCircle(BallX, BallY, 5, #PB_Pixel_Red)
Circle(BallX, BallY, 5, #RED)
; Draw the paddles
;DrawRectangle(10, Paddle1Y, 10, 50, #PB_Pixel_White)
Box(10, Paddle1Y, 10, 50, #WHITE)
;DrawRectangle(280, Paddle2Y, 10, 50, #PB_Pixel_White)
Box(280, Paddle2Y, 10, 50, #WHITE)
; Move the paddles with the mouse
Paddle1Y = MouseY() - 25
Paddle2Y = BallY - 25
; Update the screen
;UpdateWindow()
VWait()
Forever