Revisiting the Game Loop with Claude 3.7 Sonnet
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Revisiting the Game Loop with Claude 3.7 Sonnet
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.
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.
-
- 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
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.
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Revisiting the Game Loop with Claude 3.7 Sonnet
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
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
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
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
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.
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.
Re: Revisiting the Game Loop with Claude 3.7 Sonnet
P.S. In the html file the sidebar “About the Author” is a total hallucination. ;)
-Mike
-Mike
Re: Revisiting the Game Loop with Claude 3.7 Sonnet
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.
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 619 times
-
- updated-game-loop-article.html.zip
- (18.22 KiB) Downloaded 693 times
Last edited by Hutchboy on Mon Mar 03, 2025 8:53 pm, edited 1 time in total.
Re: Revisiting the Game Loop with Claude 3.7 Sonnet
Mike.
The stack from your first post works fine, but not the later one. Tried them on two different machines.
Craig
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
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
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
Mike.
I changed the word "choose" in every instance of the card script to "chooses", which is not reserved. All works fine now.
Craig
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
Craig, Thanks for the catch...already updated the stack file.