Most likely there are too many messages in the chat history or output.
Please check this document: https://www.forum.creaticode.com/topic/867/ai-openai-chatgpt
teachers from schools/organizations in partnership with CreatiCode
Most likely there are too many messages in the chat history or output.
Please check this document: https://www.forum.creaticode.com/topic/867/ai-openai-chatgpt
Flappy Bird is a simple and fun game, where the player controls the bird to fly through a few obstacles to reach its nest. There is only one control: press the SPACE key to make the bird flap.
In this tutorial, you will learn to build a simple AI program to control the bird instead of manually.
Note that this AI will be based on programming logic, rather than large language models (LLMs). That is due to 3 reasons:
The same argument also applies in many other situations, and that’s why a significant portion of AI systems will continue to be implemented using programming logic.
Now let’s get started with this simple AI program.
Open this link and remix the project:
play.creaticode.com/projects/684dbd401c49cae4509533bd
In the “AI” sprite, there are 2 stacks of code.
First, when the green flag is clicked, 3 parameters are set:
Below that, when the “start” message is received, this AI program will simply send out the “flap” message every 0.3 seconds. Each “flap” message will make the bird flap once. This is the most basic AI program, which we will improve in the next few steps.
When you click the green flag, you will find that the bird will fall to the ground. The falling speed will depend on your computer, but it will look similar to this:
This is because the “gravity
” and “flap strength
” are not fine-tuned yet. As an exercise, please adjust these 2 values. In general, “gravity” should be a number between 0 and -2 (such as -0.5), and “flap strength” should be a number between 4 and 20. Your goal should be to make the bird fly horizontally with a nice waveform trail like this:
Currently, in the forever loop, we send out the “flap” message every 0.3 seconds, and the bird will stay at the same height. Suppose we want the bird to fly higher, then we need to use a shorter interval.
Instead of 0.3 seconds, let’s use an interval of 0.03 seconds. This may be necessary if the bird needs to rise up very quickly.
As a result, when you run again, the bird should reach the ceiling very quickly and stay there:
Obviously, the current AI always makes the bird fly too high. A simple solution is to skip some flaps, so the bird will do a free fall to reach nests that are below its level.
In general, to make smart decisions, an AI needs relevant sensing data. In this case, to determine whether the bird needs to fall a bit, we can compare these 2 variables:
Your AI can access these 2 values using these 2 reporter blocks:
Now, can you change the forever loop so that the bird would not flap if it is already above the nest?
Here is one way to do it: we put the broadcast block inside an “if-then” block, so only when the nest is above the bird would the bird make a flap:
Try to run the program a few times. The nest is placed at random heights, but the bird will almost always rise or fall to its level quickly:
Now let’s move on to the next challenge: make the bird fly through the columns (pipes). Change the “columns” variable to 4, which will add 4 columns:
Obviously the bird will crash with the columns and fail. What can we do?
Similar to above, we need to provide data to the AI. Specifically, here are information about the columns:
With these information, can you try to make the bird fly through all the columns? Don’t worry about the nest for now.
In fact, all that we need to do is to replace “nestY” with the Y position of the upcoming column:
The bird should have no problem flying through all columns:
For our last step, we need to combine our solution for columns and the nest. When the bird has passed the last column, the nextColumnIndex
will be more than the columns
variable, and that’s when we should target the nest instead. Can you implement this change?
Here is an example solution:
Here is the final demo:
To practice what you have learned, here is an additional challenge for you.
Currently, the bird would only start flapping if it is below the target height (of the nest or the center of the opening), so it might fall too much below the target. If the target is very low, then the bird might touch the ground before flying back up.
To ensure the bird is always safe, it should start to flap if it is too close to the ground (Y of -240).
Currently, the playground already supports both:
And these are the same for MIT Scratch.
Hi all,
We have made some exciting new enhancements to cloud variables. The description is on this page: https://www.forum.creaticode.com/topic/1997/newly-enhanced-cloud-variables
We will post new tutorials on multiplayer games using this new feature as well. Please feel free to give us your feedback on this.
Thank you
CreatiCode
Got it. We’ll check why it happens on chromebooks.
Cloud variables are a powerful tool in MIT Scratch for creating multiplayer programs. CreatiCode has enhanced them further, making them even more capable. In this tutorial, you’ll learn how cloud variables work in the CreatiCode playground.
When creating a new variable, you can check the “cloud variable” box:
If the project is shared and opened by other users, the value of that cloud variable will be synchronized across all their computers automatically.
For example, imagine 10 users are running the same project at the same time. If one user changes the value of a cloud variable, the other 9 users will instantly see the updated value.
Here’s what happens behind the scenes:
Here is an example project: play.creaticode.com/projects/68473cea3d952dd83a76d160
It has one dog sprite with this code:
When the program starts, the sprite keeps saying the value of the cloud variable “counter”.
Whenever any user clicks the sprite, the value of “counter” increases by 1, and all other users running this program will instantly see the new value.
You can test this by opening the project in two browser windows (one normal mode and one incognito mode). Make sure you’re logged in, as cloud variables only work when you’re signed in. Of course, you can also try this with a friend on 2 computers.
Here’s what it looks like across two browsers:
To make working with variables easier, especially cloud variables, CreatiCode has added a new event block:
This block is triggered whenever the selected variable changes, i.e., when its value becomes different. Note that if you set a variable to its current value (hence no change), then this block won’t be triggered.
It works with both regular and cloud variables. This means you no longer need a forever loop to constantly check the variable — you can run code only when the value actually changes.
Here’s how we can rewrite the earlier example using this block:
You can try it here: play.creaticode.com/projects/684747163d952dd83a76d79c
MIT Scratch limits you to 10 cloud variables per project. In CreatiCode, you can use up to 100. This allows you to build much more advanced multiplayer projects.
In MIT Scratch, cloud variables:
For example, suppose your project has 2 cloud variables, then if within any second, your code updated them more than 10 times, then the extra updates will be ignored.
These limits were put in place to block users from building chat rooms, but they also make cloud variables harder to use.
In CreatiCode, cloud variables support any type of value, with some important rules:
If the value contains any letters (a–z), it must pass a moderation check to filter inappropriate content. Also, such values can only be updated once per second per user. That’s still fast enough for chat room projects.
If the value does not contain letters, and only contains numbers or symbols, like 120
or "1_23_44"
, it bypasses moderation and can be updated up to 20 times per second per user. This is useful when you want to send multiple numbers in a single update. For example, to send X = 50 and Y = 80, you can combine them into one value of "50_80"
. Also, CreatiCode does not drop any updates. Instead, these updates are queued and sent out at intervals of 50ms.
In MIT Scratch, everyone running the same shared project receives the same cloud variable updates. For example, suppose you share a multiplayer game, then all users who run this game at the same time will receive the same updates. To isolate groups, you’d have to make separate copies of the project.
CreatiCode introduces cloud sessions, which limit cloud updates to just the users in the same session. If a user hasn’t joined a session, they’re placed in the default session.
To use sessions, one user has to create one with a unique name first, then other users can join that session with the same name. Here are the2 blocks from the “Variables” category for doing so:
The session name is just a string that users agree to use. Only users in the same session will receive each other’s cloud variable updates. These blocks are boolean blocks, since they will return true or false depending on whether the action is successful.
Here’s an example program that shows how to use these blocks:
To run this program:
The project is shared here: play.creaticode.com/projects/6847509b3d952dd83a76dbfb
In MIT Scratch, cloud variables are always global: shared across all sprites and clones. This creates problems when you’re working with clones.
For instance, suppose a car sprite creates 2 clones: Clone 1 and Clone 2. If you use a global cloud variable like “facing direction,” then changing it to 90 will affect both clones, even if you only meant to rotate one.
To fix this, CreatiCode lets you create private cloud variables for each sprite or clone:
Now, each clone will have its own “direction” variable, separate from the others. For example, when one user updates the direction variable for “Clone 1”, then the direction will be updated for “Clone 1” running on all other computers, yet “Clone 2” will not be affected on any computer.
Here is an example project: play.creaticode.com/projects/6847575f1c49cae45091d685
When the green flag is clicked, the original dog sprite hides and creates two clones, with IDs 1 and 2:
When born, each clone shows itself, says its clone ID, and moves to one side of the stage:
Now, when a clone is clicked, it increases its own private cloud variable called “direction” by 15. This triggers only that clone to rotate:
As a result, when any user clicks on a dog clone, that specific clone rotates on every computer — but the other clone is unaffected:
We hope you enjoy these new features, and we can’t wait to see the amazing multiplayer projects you’ll build with them!
What device/browser are you using? Have you tried to restart the browser?