Page 1 of 1

Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Fri Feb 28, 2025 1:56 am
by Hutchboy
Hi all,

I am currently working on Game Loops and have been using Claude 3.7 Sonnet (recently upgraded from version 3.5). I wanted to share a stack that illustrates developing and timing a game loop and also to illustrate what is currently possible with A.I. After a long chat session developing the attached game loop stack I asked Claude to review the entire chat and create a detailed magazine article. I then asked Claude to take the magazine article it produced and create a visually appealing HTML version of the article. The attached HTML article is a first run with no edits. It might be worth your time to take a look at what is now possible.

My next steps with the game loop code is to work on optimization.

Happy Coding,
Mike

Note: Attachments have been superseded, see below.

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Fri Feb 28, 2025 3:41 am
by FourthWorld
Good to see you here, Mike. Will review.

Are you going to the SoCal Linux Expo next week? It'd be good to see you, and we'll have at least one other LC fan on board.

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Fri Feb 28, 2025 2:05 pm
by Hutchboy
Richard - If I were still in California I would probably attend the Linux expo, I'm sure it would be interesting.

For those working with any of the AI models and LiveCode, here is a general prompt I incorporate at the beginning of a session which has proven to be very helpful:

"Declare all variables since "strict compilation mode" will be selected in the LiveCode IDE. Use a "g" prefix for global variables, a "t" prefix for local variables and a "p" prefix for parameters. List global variables at the top of stack scripts and card scripts ahead of any handler scripts. List local variables at the beginning of the handler script in which they are used. Create short but meaningful names for variables. Double check all generated code to ensure it is valid LiveCode syntax and does not use LiveCode reserved words out of context."

-Mike

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Fri Feb 28, 2025 2:58 pm
by bn
Hi Mike,

That is amazing, the HTML page is gorgeous and the game is pretty nifty. Especially the math. However the game needs a bit of work.
Lock screen comes to mind. One of the advantages of a game loop is that you avoid a lot of screen redraws when updating the locations in a central place so you can lock the screen to reduce the redrawing overhead. However there seems to be some other bottlenecks because it starts fast and slows down then it recovers and slows down again. (apart from the overhead of the performance/debugging info fields and graphics)
A framerate of over 20 makes for a smooth animation given the step-sizes are not too large.

Thank you for making me aware of Claude Sonnet 3.7.

Kind regards
Bernd

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Sat Mar 01, 2025 1:20 am
by Hutchboy
Hi all,

Here is an update to the Game Loop stack and the HTML file. In the game loop the range of velocities cap at 1000. The number of balls caps at 100. The stress test button is for quickly setting a large number of balls and other options. I've added a toggle button to see the effect of using the native LiveCode intersect function during collision detection. Still have a few things to try then I will add in buttons instead of graphic objects so I can assign icon images to the buttons.

-Mike

Note: Attachments have been superseded, see below.

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Sat Mar 01, 2025 1:49 am
by Hutchboy
P.S. In the html file the sidebar “About the Author” is a total hallucination. ;)

-Mike

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Sat Mar 01, 2025 11:55 pm
by Hutchboy
Hi all,

The attached file updates my Game Loop explorations to include performance profiling along with other enhancements. Also, the attached HTML "tutorial" file has been expanded to correspond to this update. I've deleted the earlier versions.

Happy coding,
Mike

P.S. Revised stack per forum comments...change function in card script from "choose" to "chooseSign" to avoid reserved word conflict.

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Mon Mar 03, 2025 3:36 pm
by dunbarx
Mike.

The stack from your first post works fine, but not the later one. Tried them on two different machines.

Craig

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Mon Mar 03, 2025 4:28 pm
by dunbarx
Mike,

Dug around a bit in the card script. You have a function "function choose" in the latest version.

"Choose" is a reserved word in LC and prevents just about anything from happening. This is not present in the earlier version.

Craig

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Mon Mar 03, 2025 4:37 pm
by dunbarx
Mike.

I changed the word "choose" in every instance of the card script to "chooses", which is not reserved. All works fine now.

Craig

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Posted: Mon Mar 03, 2025 8:55 pm
by Hutchboy
Craig, Thanks for the catch...already updated the stack file.