ChatGPT

Blueforcer

Well-Known Member
Licensed User
Longtime User
im playing around with different A.I. the last months.

today ive found an awesome text based K.I. wich was released some days ago. Its from Elon Musks company openAI, wich can answer nearly everything. It can creates essay from few words, detect errors in your code, and is even able to write code for you.

While it works amazing with popular languages such C# or python i tried it with B4A. Its not perfect. but the right direction.
If B4A grows the A.I will learn more.

For example:

Promt:
Write a programm in B4A wich draws a blue car with canvas. it will move from left to right. If the car hits the screen limit it will play a sound and the screen turns red for one second. After that the car will turn around and drives to the left side again.

Answer:
Here is a simple program in Basic4Android (B4A) that draws a blue car on a canvas and moves it from left to right. If the car hits the right edge of the screen, the screen will turn red for one second and a sound will be played. After that, the car will turn around and move to the left side again.

B4X:
Sub Process_Globals
    ' Declare global variables here
    Dim CarX As Float = 0 ' Initial x-position of the car
    Dim CarSpeed As Float = 5 ' Speed of the car in pixels per frame
    Dim CarIsMovingRight As Boolean = True ' Flag to indicate the car's direction
    Dim CarWidth As Float = 50 ' Width of the car in pixels
    Dim ScreenWidth As Int ' Width of the screen in pixels
    Dim ScreenHeight As Int ' Height of the screen in pixels
    Dim CarSound As MediaPlayer ' MediaPlayer object for playing a sound
End Sub

Sub Globals
    ' Declare UI objects here
    Dim Canvas1 As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)
    ' Initialize global variables and UI objects here
    ScreenWidth = Activity.Width
    ScreenHeight = Activity.Height
 
    Canvas1.Initialize(Activity)
    Activity.AddView(Canvas1, 0, 0, ScreenWidth, ScreenHeight)
 
    ' Load and prepare the car sound
    CarSound.Initialize(2, 100, False)
    CarSound.Load(File.DirAssets, "car_crash.mp3")
End Sub

Sub Activity_Resume
    ' Start the animation loop
   Draw
End Sub

Sub Draw
    ' This event is called every time the canvas needs to be redrawn
    Dim CarColor As Int = Colors.Blue ' Color of the car
    Dim CrashColor As Int = Colors.Red ' Color of the screen during a crash
 
    ' Update the car position
    If CarIsMovingRight Then
        CarX = CarX + CarSpeed
    Else
        CarX = CarX - CarSpeed
    End If
 
    ' Check if the car has hit the screen limit
    If CarX + CarWidth >= ScreenWidth Then
        ' The car has hit the right edge of the screen
        CarIsMovingRight = False ' Change direction
        CarX = ScreenWidth - CarWidth ' Make sure the car is not outside the screen
        CarSound.Play ' Play a sound
        Canvas.DrawColor(CrashColor) ' Turn the screen red
        Sleep(1000) ' Wait for 1 second
        Canvas.DrawColor(Colors.Transparent) ' Clear the screen
    ElseIf CarX <= 0 Then
        ' The car has hit the left edge of the screen
        CarIsMovingRight = True ' Change direction
        CarX = 0 ' Make sure the car is not outside the screen
    End If
 
    ' Draw the car
    Canvas.DrawRect(CarColor, CarX, 100, CarWidth, 100, True, True)
 
    ' Schedule the next frame
    Canvas1.Invalidate
    Sleep(100)
    Draw ' This will call the Draw event again
End Sub

Note: This code is for demonstration purposes only and is not guaranteed to be free of errors or bugs.
 

Sandman

Expert
Licensed User
Longtime User
Welcome to the party. ?
 

Blueforcer

Well-Known Member
Licensed User
Longtime User
Welcome to the party. ?
Crazy.. i searched for ChatGPT before my post and found nothing..
im sorry, so post can be deleted
 

mcqueccu

Well-Known Member
Licensed User
Longtime User
It even has an older thread before thes two. I will look for the thread

Edit: Sorry, It was GPT-3 and Github Co-pilot
 
Last edited:
Top