New games every week!
Coding With AI Blog
6th March 2023
There's a GotoJSE game at the ready, but I haven't yet done the video or uploads or any of that stuff.

-=-=-

Instead, then, I spent most of last night faffing about with ChatGPT once more.
I figured it'd be nice to have a quick example that could easily teach ChatGPT the fundamentals of the language, all in one quick and simple go.
With that in mind, then, I crafted the following code.

// GotoJSE Example // by Jayenkai // Created 2023/3/5 // Set up the Screen Graphics 800,600:Border 30,30,90 // Define main variables w=ScreenWidth() // The full screen size h=ScreenHeight() w2=w/2 // Half of the screen size, useful for centring things on the screen. h2=h/2 w4=w2/2 // Quarter of the screen, in case we need it. h4=h2/2 PosX=w2 PosY=h2 Message$="Hello World" // Array Declarations Dim NumF(10,3) // Create a 10x3 array Dim NumI(10,3) // Create a second array for m=0 to 9 for n=0 to 2 NumF(m,n)=Rnd(100) NumI(m,n)=Rand(100) next next Repeat // Main loop CLS 64,64,64 // Clear the screen in Dark Gray Starfield 0,2 // Speed of starfield, X=0, Y=2, so starfield falls down the screen For m=0 to 9 ResetDraw // Resets color, rotation, scale, linethickness, fontsize, etc. angle=((m*36)+(Mills()*0.1)) % 360 x=PosX+Cos(angle)*w4 y=PosY+Sin(angle)*h4 SetRot Mills()*0.1 SetSize Sin(angle)+1,Cos(angle)+1 If m==0 then SetColor 0,0,0:Text x,y,"Hello",1 // Where the 1 = Centered text If m==5 then SetFontSize 32:SetHue angle,1,1:Text x,y,"World",1 If m==1 // Rectangle SetHue angle*2,1,0.5 Rect x,y,32,32,1 // x,y,width,height,centered Endif If m==2 // Oval SetHue angle*4,0.5,1 // Hue, Sat, Value Oval x,y,32,32,32 // x,y,width,height,sides of oval Endif If m==3 // Triangle SetColor angle*0.3,angle*0.5,angle*0.7 // Red, Green, Blue Circle x,y,32,32,3 // x,y,width,height,sides of circle. EndIf if m==4 then SetColor 0,120,255:Line PosX,PosY,x,y if m==6 // Star SetColor 255,255,0 a=64 if GamePad(ButtonA)>0.5 then a=160 // Make the star bigger if the A Button is being held. b=a/2 Star x,y,a,b,5 // x,y,Outer Size, Inner Size, Points endif if m==7 SetFontSize 32 Emoji x,y,"1F600",1 // To draw Emoji, we use the Emoji command. We need to use the last 5 hexadecimal characters of its unicode value.. eg 1F39A is a Level Slider endif if m==8 // Time ResetDraw SetColor 0,0,0 Text x,y,TimeString(),1 // TimeString() is the current time, "H:M:S", centered at x,y hours=TimeHour():mins=TimeMinute():secs=TimeSeconds() // other time values. days=DateDay():months=DateMonth():years=DateYear() // other time values. endif SetThick 8 if m==9 then SetColor 120,255,0:Line PosX,PosY,x,y ResetDraw:SetColor 0,0,0 for n=0 to 2 x=PosX+Cos(angle)*32*(n+1) y=PosY+Sin(angle)*32*(n+1) Text x,y,NumI(m,n),1 x=PosX+Cos(angle)*32*(n+10) y=PosY+Sin(angle)*32*(n+10) Text x,y,NumF(m,n),1 next Next // Move Center using Joypad or Cursor Keys PosX=PosX+((GamePad(ButtonRight)-GamePad(ButtonLeft))*4) PosY=PosY+((GamePad(ButtonDown)-GamePad(ButtonUp))*4) Gosub AddMessage Flip // Display the drawn content and wait for VBL Forever // Main loop .AddMessage // A small subroutine Text w2,h-16,Message$,1 Return // Return from the subroutine


It, hopefully, allows the AI to see the basic layout of the code, how most of the commands work, and .. with any luck, how to program simple little mini scripts.

If you start a conversation with "Hi ChatGPT. Here's an example of the GotoJSE Language", and then paste the example above, you should then be able to ask it to code little test scripts.
You might also be able to guide it towards making something more substantial. Who knows.

Here's a quick clock face that I got ChatGPT to create in just a couple of requests.

// GotoJSE Analogue Clock Example with Swirly Background // by [Your Name] // Created [Current Date] // Set up the Screen Graphics 800,600:Border 30,30,90 // Define main variables w=ScreenWidth() // The full screen size h=ScreenHeight() w2=w/2 // Half of the screen size, useful for centring things on the screen. h2=h/2 // Define swirly lines variables angle = 0 radius = 0 lineStep = 0.2 lineLength = 300 lineSpacing = 10 // Main loop Repeat CLS 0,0,0 // Clear the screen in black // Draw swirly lines For y = 0 to h Step lineSpacing angle = ((y / h) + (Mills() / 1000)) * 360 radius = (y / h) * 200 SetHue angle // Set the line color based on the angle x1 = w2 + Cos(angle)*radius y1 = y x2 = w2 + Cos(angle)*radius + Cos(angle+90)*lineLength y2 = y + Sin(angle+90)*lineLength SetThick 2 Line x1,y1,x2,y2 Next // Draw clock face SetColor 255,255,255 SetThick 8 Circle w2, h2, 200, 200, 60 // x, y, width, height, sides of circle. // Draw clock markings SetThick 4 SetColor 255,255,255 For i = 1 To 12 angle = i*30 x1 = w2 + Cos(angle)*180 y1 = h2 + Sin(angle)*180 x2 = w2 + Cos(angle)*190 y2 = h2 + Sin(angle)*190 Line x1,y1,x2,y2 Next // Draw clock hands hour = TimeHour() % 12 minute = TimeMinute() second = TimeSeconds() // Hour Hand SetThick 16 SetColor 255,0,0 angle = (hour*30) + (minute*0.5) x1 = w2 y1 = h2 x2 = w2 + Cos(angle)*120 y2 = h2 + Sin(angle)*120 Line x1,y1,x2,y2 // Minute Hand SetThick 12 SetColor 0,255,0 angle = minute*6 x1 = w2 y1 = h2 x2 = w2 + Cos(angle)*160 y2 = h2 + Sin(angle)*160 Line x1,y1,x2,y2 // Second Hand SetThick 4 SetColor 0,0,255 angle = second*6 x1 = w2 y1 = h2 x2 = w2 + Cos(angle)*180 y2 = h2 + Sin(angle)*180 Line x1,y1,x2,y2 Flip // Display the drawn content and wait for VBL Forever


Of course, I've had to edit and tweak the example code numerous times since last night, to give it all manner of tips and tricks that it can learn from, but I think the example's good enough for a few mini scripts.
Goodness me!
Technology, eh!?

In a matter of months, we'll be getting it to write games of my own quality!


"A beautiful oil painting of Derek Man sitting with his laptop on his desk, in the dark. The bright screen lights up his face. Volumetric lighting. HDR. 4K"
Views 15, Upvotes 2  
Daily Blog , Ai
New games every week!
Site credits : If you can see it, Jayenkai did it.
(c) Jayenkai 2023 and onwards, RSS feed

Blog - Coding With AI - AGameAWeek