Discuss Scratch

ElsieBreeze
Scratcher
100+ posts

Cross-language workaround

Maximouse wrote:

Sheep_maker wrote:

R4356th wrote:

NxNmultiply wrote:

R4356th wrote:

snip

I haven't ever seen an environment where printf makes Scratch style speech appear, overwriting the previous one.
Yeah, but in a way, it does the same thing. Says or prints something.
One could argue that it isn't sufficient because the text can't be hidden afterwards, so there can't be a
say [Hello!] for (2) secs
Scratchers also use the say block for an animated dialogue reveal, which reveals each letter every frame, but with your workaround it would result in triangular text:
H
He
Hel
Hell
Hello
Hello!
Previous output can be hidden by printing a carriage return.
Not really?
That just goes to the next line, a standard terminal has 25 lines, but on modern systems the standard is rarely followed that closely.
Plus… you'll end up only printing at the bottom.

On systems that support ANSI escape codes You could print.
"\n\033[1A     \n\033[1A"
(with more spaces between the \033[1A and \n depending on length of last line.

Greetings! I'm ElsieBreeze (but y'all can call me Elsie). I'm just a girl who loves to code, nothing too extravagant

I run Windows 10 in a Virtual Machine for Gaming:tm: and Gentoo/Linux on my main system. DNS over Tor is fun.

Like Tetris? Try https://xnopyt.com/js-tetris.html Or, for a twist: https://xnopyt.com/js-pentris.html
ElsieBreeze
Scratcher
100+ posts

Cross-language workaround

NxNmultiply wrote:

ElsieBreeze wrote:

NxNmultiply wrote:

R4356th wrote:

say []
in C:
 
printf( )
For it to work you have to also position the cursor (#include <windows.h> SetConsoleCursorPosition(hConsole, {X, Y});) at the location of speech, which would be somewhat complicated to determine.
If only Windows handled the console sensibly like Linux does.
?
Windows forces you to do stuff through windows.h (and in turn the Win32 API), whereas on Linux, most terminals support ANSI escape codes which make sense and work.

Greetings! I'm ElsieBreeze (but y'all can call me Elsie). I'm just a girl who loves to code, nothing too extravagant

I run Windows 10 in a Virtual Machine for Gaming:tm: and Gentoo/Linux on my main system. DNS over Tor is fun.

Like Tetris? Try https://xnopyt.com/js-tetris.html Or, for a twist: https://xnopyt.com/js-pentris.html
Maximouse
Scratcher
1000+ posts

Cross-language workaround

ElsieBreeze wrote:

Not really?
That just goes to the next line, a standard terminal has 25 lines, but on modern systems the standard is rarely followed that closely.
Plus… you'll end up only printing at the bottom.

On systems that support ANSI escape codes You could print.
"\n\033[1A     \n\033[1A"
(with more spaces between the \033[1A and \n depending on length of last line.
By carriage return I mean the \r character, which does overwrite previous output. This C++ code:
#include <cstdio>
int main()
{
    printf("hello\rhi\n"); 
}
outputs “hillo”.

You are reading Maximouse's signature. Learn more about signatures
Click here to make pixel art.
Be strong

My forum stats
NxNmultiply
Scratcher
100+ posts

Cross-language workaround

ElsieBreeze wrote:

NxNmultiply wrote:

?
Windows forces you to do stuff through windows.h (and in turn the Win32 API), whereas on Linux, most terminals support ANSI escape codes which make sense and work.
The Command Prompt has features pretty much unique to Microsoft Windows, and therefore your comparison makes no sense. Instead of comparing stay on topic and construct cross-language workaround.

WriteConsoleOutput can conveniently write a rectangle from an array of characters and attributes, so for speech blocks you could put the frame and text in the CHAR_INFO array and output that, and if you're done overwrite it with the remaining layers.

Last edited by NxNmultiply (May 6, 2020 10:41:06)

Maximouse
Scratcher
1000+ posts

Cross-language workaround

ElsieBreeze wrote:

Windows forces you to do stuff through windows.h (and in turn the Win32 API), whereas on Linux, most terminals support ANSI escape codes which make sense and work.
The new open source Windows Terminal does support ANSI escape codes.

You are reading Maximouse's signature. Learn more about signatures
Click here to make pixel art.
Be strong

My forum stats
Boomer001
Scratcher
1000+ posts

Cross-language workaround

<<A> and <B>>
in JavaScript:
A && B
<<A> or <B>>
in JavaScript:
A || B

Be moist Be very moisty moist And stay moist Be the opposite of dry

Press alt+f4 for free follows.



















Maximouse
Scratcher
1000+ posts

Cross-language workaround

Boomer001 wrote:

<<A> and <B>>
in JavaScript:
A && B
<<A> or <B>>
in JavaScript:
A || B
I believe this also works at least in C, C++, C# and Java.

In Python it's even simpler:
<<A::grey> and <B::grey>>
A and B
<<A::grey> or <B::grey>>
A or B

You are reading Maximouse's signature. Learn more about signatures
Click here to make pixel art.
Be strong

My forum stats
Sheep_maker
Scratcher
1000+ posts

Cross-language workaround

Boomer001 wrote:

<<A> and <B>>
in JavaScript:
A && B
<<A> or <B>>
in JavaScript:
A || B
This is not a perfect workaround because Scratch does not short circuit. This is especially apparent if custom reporters existed, but this can still be observed using extensions and looking at the Network tab in developer tools:
<<(translate [FIRST] to [Polish v]::extension) = [50]> and <(translate [SECOND] to [Polish v]::extension) = [50]>>
Both requests are logged in the Network tab, so even though the first input reports false, the second input is evaluated anyways.

This wouldn't be the case in most other programming languages.

Also, the JavaScript || operator can return a non-boolean. However, the or block in Scratch only returns true or false:
<<[truthy string]::extension> or <>>
The string input in boolean reporter block is from my Utilities extension
This is only the case in Scratch 3.0; in Scratch 2.0 based on the Scrap mod, it seems the or block can return a string.

So a better JavaScript equivalent might be:
function or (a, b) {
  return !!(a || b)
}

- Sheep_maker This is a kumquat-free signature. :P
This, my signature, appears below all my posts. Discuss it on my profile, not the forums. Here's how to make your own.
Post count: more than 6
.postsignature { overflow: auto; } .scratchblocks { overflow-x: auto; overflow-y: hidden; }
NxNmultiply
Scratcher
100+ posts

Cross-language workaround

Maximouse wrote:

ElsieBreeze wrote:

Windows forces you to do stuff through windows.h (and in turn the Win32 API), whereas on Linux, most terminals support ANSI escape codes which make sense and work.
The new open source Windows Terminal does support ANSI escape codes.
I'm not talking about that stuff. Compiled C++ applications run in a command prompt. If you compiled to Windows Terminal instead it would only run on Windows 10, making the program virtually useless. And if you conditionally use either you'd make the Windows 10 experience inconsistent for no reason.

Last edited by NxNmultiply (May 7, 2020 06:24:32)

ElsieBreeze
Scratcher
100+ posts

Cross-language workaround

NxNmultiply wrote:

Maximouse wrote:

ElsieBreeze wrote:

Windows forces you to do stuff through windows.h (and in turn the Win32 API), whereas on Linux, most terminals support ANSI escape codes which make sense and work.
The new open source Windows Terminal does support ANSI escape codes.
If you compiled to Windows Terminal instead it would only run on Windows 10, making the program virtually useless.
No? You don't “compile to Windows Terminal”. It's just that, a terminal. It can run Command Prompt, WSL, Bash, Zsh, etc through it.

Also… it seems that Windows does support VT100 Escape Codes, so long as you set a certain flag beforehand https://docs.microsoft.com/en-us/windows/console/console-virtual-terminal-sequences

Maximouse wrote:

ElsieBreeze wrote:

Windows forces you to do stuff through windows.h (and in turn the Win32 API), whereas on Linux, most terminals support ANSI escape codes which make sense and work.
The new open source Windows Terminal does support ANSI escape codes.
It does, but I've had applications spit own the escape codes as text, rather than them performing their job. It seems hit or miss, and likely related to how the application was compiled, I believe. For the majority, it works perfectly fine, however. Especially via Cygwin Zsh.

NxNmultiply wrote:

WriteConsoleOutput can conveniently write a rectangle from an array of characters and attributes, so for speech blocks you could put the frame and text in the CHAR_INFO array and output that, and if you're done overwrite it with the remaining layers.
This is interesting functionality that I've not heard of before, could you provide some code examples and/or links to code examples. It sounds fascinating.

Maximouse wrote:

By carriage return I mean the \r character, which does overwrite previous output. This C++ code:
#include <cstdio>
int main()
{
    printf("hello\rhi\n"); 
}
outputs “hillo”.
Ach! My mistake sorry, I confuse carriage return and line feed wayyyy too often

Greetings! I'm ElsieBreeze (but y'all can call me Elsie). I'm just a girl who loves to code, nothing too extravagant

I run Windows 10 in a Virtual Machine for Gaming:tm: and Gentoo/Linux on my main system. DNS over Tor is fun.

Like Tetris? Try https://xnopyt.com/js-tetris.html Or, for a twist: https://xnopyt.com/js-pentris.html
Maximouse
Scratcher
1000+ posts

Cross-language workaround

ElsieBreeze wrote:

NxNmultiply wrote:

WriteConsoleOutput can conveniently write a rectangle from an array of characters and attributes, so for speech blocks you could put the frame and text in the CHAR_INFO array and output that, and if you're done overwrite it with the remaining layers.
This is interesting functionality that I've not heard of before, could you provide some code examples and/or links to code examples. It sounds fascinating.
https://docs.microsoft.com/en-us/windows/console/reading-and-writing-blocks-of-characters-and-attributes

You are reading Maximouse's signature. Learn more about signatures
Click here to make pixel art.
Be strong

My forum stats
Scratch---Cat
Scratcher
1000+ posts

Cross-language workaround

lt seems that nobody has ever talked about motion blocks yet.

h.r wrote:

move (10) steps :: motion
FD 10


h.r wrote:

move backward (10) steps :: motion
BK 10

h.r wrote:

turn (90) @turnRight degrees :: motion
RT 90

h.r wrote:

turn (90) @turnLeft degrees :: motion
LT 90

h.r wrote:

show :: looks
ST

h.r wrote:

hide :: looks
HT


h.r wrote:

repeat (10) {
} :: control cap loop
REPEAT 10 [ ] 

Download Scratch 2.0 | Check your messages | Check my messages
_____________________________________________________________________________________________________

If you want to subscribe to this forum topic, please click the
{} Follow Discussion :: ring sensing
button below this forum post! Thanks!

NxNmultiply
Scratcher
100+ posts

Cross-language workaround

Scratch---Cat wrote:

lt seems that nobody has ever talked about motion blocks yet.

h.r wrote:

move (10) steps :: motion
FD 10

You mean in a language named h.r?
Scratch---Cat
Scratcher
1000+ posts

Cross-language workaround

NxNmultiply wrote:

Scratch---Cat wrote:

lt seems that nobody has ever talked about motion blocks yet.

h.r wrote:

move (10) steps :: motion
FD 10

You mean in a language named h.r?
Nope.

Download Scratch 2.0 | Check your messages | Check my messages
_____________________________________________________________________________________________________

If you want to subscribe to this forum topic, please click the
{} Follow Discussion :: ring sensing
button below this forum post! Thanks!

Maximouse
Scratcher
1000+ posts

Cross-language workaround

Scratch---Cat wrote:

NxNmultiply wrote:

Scratch---Cat wrote:

lt seems that nobody has ever talked about motion blocks yet.

h.r wrote:

move (10) steps :: motion
FD 10

You mean in a language named h.r?
Nope.
It's Logo, right?

You are reading Maximouse's signature. Learn more about signatures
Click here to make pixel art.
Be strong

My forum stats
Boomer001
Scratcher
1000+ posts

Cross-language workaround

move (10) steps
In Tosh:
move 10 steps
Lol this one is really easy :P

Be moist Be very moisty moist And stay moist Be the opposite of dry

Press alt+f4 for free follows.



















R4356th
Scratcher
1000+ posts

Cross-language workaround

Boomer001 wrote:

move (10) steps
In Tosh:
move 10 steps
Lol this one is really easy :P
LOL. Syntax in tosh is the same as Scratch(2.0).
Boomer001
Scratcher
1000+ posts

Cross-language workaround

R4356th wrote:

Boomer001 wrote:

move (10) steps
In Tosh:
move 10 steps
Lol this one is really easy :P
LOL. Syntax in tosh is the same as Scratch(2.0).
Exactly

Be moist Be very moisty moist And stay moist Be the opposite of dry

Press alt+f4 for free follows.



















Sheep_maker
Scratcher
1000+ posts

Cross-language workaround

In Minecraft (Java) commands then:
move (10) steps
turn cw (15) degrees
turn ccw (15) degrees

show
hide
tp @s ^ ^ ^10
tp @s ~ ~ ~ ~15 ~
tp @s ~ ~ ~ ~-15 ~

# depends on the mob; this is for an armour stand:
data modify entity @s Invisible set value 0b
data modify entity @s Invisible set value 1b
For repeat, I guess one could use recursion:
# main.mcfunction
# Assumes the scoreboard value of `iterations` in `vars` is the number of loops
function example:repeat

# repeat.mcfunction
# ...
scoreboard players remove iterations vars 1
execute if score iterations vars matches 1.. run function example:repeat

- Sheep_maker This is a kumquat-free signature. :P
This, my signature, appears below all my posts. Discuss it on my profile, not the forums. Here's how to make your own.
Post count: more than 6
.postsignature { overflow: auto; } .scratchblocks { overflow-x: auto; overflow-y: hidden; }
Boomer001
Scratcher
1000+ posts

Cross-language workaround

if <input> then
...
end
in Python:
if input:
   ...
in JavaScript:
if (input) {
   ...
};
if <input> then
...
else
...
end
in Python:
if input:
   ...
else:
   ...
in JavaScript:
if (input) {
   ...
} else {
   ...
};

Last edited by Boomer001 (May 29, 2020 17:34:38)


Be moist Be very moisty moist And stay moist Be the opposite of dry

Press alt+f4 for free follows.



















Powered by DjangoBB

Standard | Mobile