Revisiting the Game Loop with Claude 3.7 Sonnet

Creating Games? Developing something for fun?

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Hutchboy
Posts: 123
Joined: Wed Aug 01, 2018 2:57 pm
Contact:

Revisiting the Game Loop with Claude 3.7 Sonnet

Post by Hutchboy » Fri Feb 28, 2025 1:56 am

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.
Last edited by Hutchboy on Sun Mar 02, 2025 12:10 am, edited 2 times in total.

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10053
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Post by FourthWorld » Fri Feb 28, 2025 3:41 am

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Hutchboy
Posts: 123
Joined: Wed Aug 01, 2018 2:57 pm
Contact:

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Post by Hutchboy » Fri Feb 28, 2025 2:05 pm

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

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4174
Joined: Sun Jan 07, 2007 9:12 pm

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Post by bn » Fri Feb 28, 2025 2:58 pm

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

Hutchboy
Posts: 123
Joined: Wed Aug 01, 2018 2:57 pm
Contact:

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Post by Hutchboy » Sat Mar 01, 2025 1:20 am

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.
Last edited by Hutchboy on Sun Mar 02, 2025 12:10 am, edited 2 times in total.

Hutchboy
Posts: 123
Joined: Wed Aug 01, 2018 2:57 pm
Contact:

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Post by Hutchboy » Sat Mar 01, 2025 1:49 am

P.S. In the html file the sidebar “About the Author” is a total hallucination. ;)

-Mike

Hutchboy
Posts: 123
Joined: Wed Aug 01, 2018 2:57 pm
Contact:

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Post by Hutchboy » Sat Mar 01, 2025 11:55 pm

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.
Attachments
New Optimized Game Loop with Profiling.livecode.zip
Fixed per forum comments
(19.28 KiB) Downloaded 620 times
updated-game-loop-article.html.zip
(18.22 KiB) Downloaded 695 times
Last edited by Hutchboy on Mon Mar 03, 2025 8:53 pm, edited 1 time in total.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Post by dunbarx » Mon Mar 03, 2025 3:36 pm

Mike.

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

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Post by dunbarx » Mon Mar 03, 2025 4:28 pm

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

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10337
Joined: Wed May 06, 2009 2:28 pm

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Post by dunbarx » Mon Mar 03, 2025 4:37 pm

Mike.

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

Craig

Hutchboy
Posts: 123
Joined: Wed Aug 01, 2018 2:57 pm
Contact:

Re: Revisiting the Game Loop with Claude 3.7 Sonnet

Post by Hutchboy » Mon Mar 03, 2025 8:55 pm

Craig, Thanks for the catch...already updated the stack file.

Post Reply