Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Scratch to C++ translation and how to make it better
- medians
-
Scratcher
1000+ posts
Scratch to C++ translation and how to make it better
Are you trying to pretend to be me?There is dragging mode now! YeahWhat's dragging mode?
Okay, maybe not lolYeah, this would be pretty confusing to implement in C++. There was a proposal to add this (doc), but it wasn't implemented. The OP can ignore edge cases like these for now, however.when gf clicked
set [num v] to (342)
set [num v] to (join [0o] (num))
change [num v] by (1)
say (num) // 227
Last edited by medians (May 16, 2023 03:24:17)
- liavka
-
Scratcher
47 posts
Scratch to C++ translation and how to make it better
WhoAre you trying to pretend to be me?There is dragging mode now! YeahWhat's dragging mode?Okay, maybe not lolYeah, this would be pretty confusing to implement in C++. There was a proposal to add this (doc), but it wasn't implemented. The OP can ignore edge cases like these for now, however.when gf clicked
set [num v] to (342)
set [num v] to (join [0o] (num))
change [num v] by (1)
say (num) // 227
- WojtekGame
-
Scratcher
1000+ posts
Scratch to C++ translation and how to make it better
when will be the whole project done (and even adding some TW support if you can.)
- liavka
-
Scratcher
47 posts
Scratch to C++ translation and how to make it better
when will be the whole project done (and even adding some TW support if you can.)Idk.. What I can say is I don't think it will be ready in this month. Since there is no sound functions at all. Rn I'm debugging/refactoring it, so that I can move to the next blocks painless.
But you can check the blocks list. It's growing little by little
https://github.com/MiloLug/c-scratch/blob/main/docs/scratch_functionality.md
- liavka
-
Scratcher
47 posts
Scratch to C++ translation and how to make it better
Phew… Spent another day on improvements and fixes. There are now Const, Var and Arg types for storing values. I thought before that simply passing everything by auto and reference will be enough, but it just started falling apart with more complex code. And at the same time I couldn't make all the arguments into Vars, since it's too heavy to initialize.
And it's safe now to pass any (string/number) data to functions using Arg without overhead of copying strings in some cases etc.
Soo… I think it's time to move to implementing more blocks.
Var test1 = L“lol”;
Corouting testFunction(Arg something) {
test1 = 3;
cs_print(something); // before it would print 3
cs_stop;
}
And it's safe now to pass any (string/number) data to functions using Arg without overhead of copying strings in some cases etc.
Soo… I think it's time to move to implementing more blocks.
Last edited by liavka (May 18, 2023 14:24:20)
- WojtekGame
-
Scratcher
1000+ posts
Scratch to C++ translation and how to make it better
Phew… Spent another day on improvements and fixes. There are now Const, Var and Arg types for storing values. I thought before that simply passing everything by auto and reference will be enough, but it just started falling apart with more complex code. And at the same time I couldn't make all the arguments into Vars, since it's too heavy to initialize.i think we can use std::string though because it's the built-in.Var test1 = L“lol”;
Corouting testFunction(Arg something) {
test1 = 3;
cs_print(something); // before it would print 3
cs_stop;
}
And it's safe now to pass any (string/number) data to functions using Arg without overhead of copying strings in some cases etc.
Soo… I think it's time to move to implementing more blocks.
however numbers can use std::string too, but it's better in a int.
- liavka
-
Scratcher
47 posts
Scratch to C++ translation and how to make it better
Phew… Spent another day on improvements and fixes. There are now Const, Var and Arg types for storing values. I thought before that simply passing everything by auto and reference will be enough, but it just started falling apart with more complex code. And at the same time I couldn't make all the arguments into Vars, since it's too heavy to initialize.i think we can use std::string though because it's the built-in.Var test1 = L“lol”;
Corouting testFunction(Arg something) {
test1 = 3;
cs_print(something); // before it would print 3
cs_stop;
}
And it's safe now to pass any (string/number) data to functions using Arg without overhead of copying strings in some cases etc.
Soo… I think it's time to move to implementing more blocks.
however numbers can use std::string too, but it's better in a int.
In short, Var (and so Arg, Const) allow to store both numbers and strings.
Actually, I have my own String here, since it allows me to have more control over memory etc. But not only the string. Since storing numbers as strings is just… Strange ._.
I don't use neither std::string nor numbers alone. As I said, there is Var and Arg (Const is just a base for them). And they allow you to store both strings and numbers dynamically. They also manage string-to-number and number-to-string things so you can do
Var t = 0;
t = join(1, t);
t = t + L“20”;
cs_print(t); // prints 30
And with Arg you can do the same (it's just an optimized version of Var for passing values to a function).
Coroutine myFunction(Arg x, Arg y) {
cs_print(x + y);
cs_stop;
}
// they all work fine:
cs_wait myFunction(L“220”, 11);
cs_wait myFunction(1, 2);
cs_wait myFunction(10, L“0xFFF”);
In case you don't know about that L prefix - it's just for unicode strings support.
So the strings and numbers logic is finished. Rn I just need to add the rest of the blocks.
Last edited by liavka (May 18, 2023 15:37:55)
- liavka
-
Scratcher
47 posts
Scratch to C++ translation and how to make it better
Welp, I've made some improvements and now it's able to compile and run on windows with mingw. Both with gcc and clang variants
- liavka
-
Scratcher
47 posts
Scratch to C++ translation and how to make it better
Yo! It works fine for mingw-gcc/-clang and Visual Studio (latest) with Clang-CL or MSVC.
In other words, you can try it now on Windows. You just need the latest Visual Studio or MinGW with CMake.
In Visual Studio you have to enable C++ and CMake tools support.
Then just download the project ( https://github.com/MiloLug/c-scratch ) and open its folder in the studio.
In other words, you can try it now on Windows. You just need the latest Visual Studio or MinGW with CMake.
In Visual Studio you have to enable C++ and CMake tools support.
Then just download the project ( https://github.com/MiloLug/c-scratch ) and open its folder in the studio.
Last edited by liavka (May 24, 2023 07:31:32)
- WojtekGame
-
Scratcher
1000+ posts
Scratch to C++ translation and how to make it better
bumping something due to being written in C++ (it's an flavor i guess)
- feba13
-
Scratcher
47 posts
Scratch to C++ translation and how to make it better
You can't, but if you want to put your scratch game onto C++, just ask someone who knows C++ and how to use it, so they can teach you.
when I receive [found someone v]
say [Can you teach me C++]
wait until <they answer>
if <they answer, yes> then
they'll teach you
else
ask someone else
end
- Discussion Forums
- » Advanced Topics
-
» Scratch to C++ translation and how to make it better