Discuss Scratch

rj8wjeiw
New to Scratch
10 posts

Cross-language workaround

It's like the Scratch workaround challenge, but with a twist — Scratch blocks are workarounded in different programming languages

Ok so

<key [ v] pressed?>

In C++, Windows 2000 and up:

#import <stdint.h>
#import <windows.h>
bool key(uint8_t id){
return bool((uint16_t(GetAsyncKeyState(id)) >> 15);
}

where the IDs are documented at https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes .
Yyyyyy754
New to Scratch
12 posts

Cross-language workaround

(()+())

In C++:

double add(double x, double y){
return double(double(x) + double(y));
}

Pretty sure, that should work for variables stored as doubles, but not for strings. So, it is a partial workaround.

clear

#import <stdint.h>
uint32_t pen[172800];
uint8_t clear(){
for (uint32_t i=0; i<172800; i++){
pen[i] &= 0x00FFFFFF;
}
}
badatprogrammingibe
Scratcher
500+ posts

Cross-language workaround

Yyyyyy754
New to Scratch
12 posts

Cross-language workaround

<<> or <>>
In C++
bool or(bool a, bool b){
    return bool(bool(a)||bool(b));
}
ElsieBreeze
Scratcher
100+ posts

Cross-language workaround

define add (a) (b)
set [return v] to ((a) + (b))

In OCaml
let add a b = a + b;;

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
Sheep_maker
Scratcher
1000+ posts

Cross-language workaround

((a) mod (b))
JavaScript:
function mod (a, b) {
  return (a % b + b) % b
}
 
mod(a, b)
Scheme:
(modulo a b)
((a) + (b))
JavaScript:
+a + +b
(join (a) (b))
JavaScript:
'' + a + b
// or
`${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; }
Tdth
New to Scratch
10 posts

Cross-language workaround

(letter (3) of [world])

In C++

"world"[3-1];

stop [this project v]
(Or stop all, etc. depending on Scratch version)

return 1/0; //chaotic operation, cannot be done on integers
NxNmultiply
Scratcher
100+ posts

Cross-language workaround

(()mod())

The modulo operation does not exist on doubles, it is only a mathematical abstraction of Scratch (and Javascript). Therefore it must be implemented in software, therefore long double to handle intermediate precision.

In C++

double mod(double a, double b){
    long double c = (a/b);
    long double d = 0;
    long double e;
    while((c-d)<0){
        e = 1;
        do{
            e *= 2;
        }while(e<=(d-c));
        e /= 2;
        d -= e;
    }
    while((c-d)>=1){
        e = 1;
        do{
            e *= 2;
        }while(e<=(c-d));
        e /= 2;
        d += e;
    }
    return (a-(d*b));
}
Sheep_maker
Scratcher
1000+ posts

Cross-language workaround

NxNmultiply wrote:

(()mod())

The modulo operation does not exist on doubles, it is only a mathematical abstraction of Scratch (and Javascript). Therefore it must be implemented in software, therefore long double to handle intermediate precision.
Doesn't C++ have the % operator? It should be roughly identical to JavaScript's %, which is a remainder operator, so I think you could just translate Scratch's implementation of the mod block:
double mod(double n, double modulus) {
  double result = n % modulus;
  if (result / modulus < 0) result += modulus;
  return result;
}

- 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; }
A-E-
Scratcher
100+ posts

Cross-language workaround

stop [all v]
In JS:
function stopAll(){
window.close()
setTimeout(()=>{
while(1){
alert("Close this page!")
}
},100)
}
NxNmultiply
Scratcher
100+ posts

Cross-language workaround

R4356th wrote:

say []
in C++:
printf ()
Uhh, this function appends text to console output, not changes the graphical speech visualization.
R4356th
Scratcher
1000+ posts

Cross-language workaround

NxNmultiply wrote:

R4356th wrote:

say []
in C++:
printf ()
Uhh, this function appends text to console output, not changes the graphical speech visualization.
What do you mean?
OurPrincess
Scratcher
1000+ posts

Cross-language workaround

say []
in HTML:
<p></p>

officially moved to @-liffeydays- and @-TheLatest-
R4356th
Scratcher
1000+ posts

Cross-language workaround

OurPrincess wrote:

say []
in HTML:
<p></p>
Well, technically, that is not a workaround in HTML it just writes text in a webpage.

Last edited by R4356th (March 27, 2020 12:21:51)

OurPrincess
Scratcher
1000+ posts

Cross-language workaround

R4356th wrote:

OurPrincess wrote:

say []
in HTML:
<p></p>
Well, technically, that is not a workaround in HTML it just writes text in a webpage.
I don't know, import an image or something?

officially moved to @-liffeydays- and @-TheLatest-
R4356th
Scratcher
1000+ posts

Cross-language workaround

OurPrincess wrote:

I don't know, import an image or something?
Have you developed a website before? If you haven't then go to this link and see the demo:
https://www.w3schools.com/html/tryit.asp?filename=tryhtml_default
OurPrincess
Scratcher
1000+ posts

Cross-language workaround

R4356th wrote:

OurPrincess wrote:

I don't know, import an image or something?
Have you developed a website before? If you haven't then go to this link and see the demo:
https://www.w3schools.com/html/tryit.asp?filename=tryhtml_default
I've made many websites! Some with a website maker, others with HTML!

officially moved to @-liffeydays- and @-TheLatest-
R4356th
Scratcher
1000+ posts

Cross-language workaround

OurPrincess wrote:

R4356th wrote:

OurPrincess wrote:

I don't know, import an image or something?
Have you developed a website before? If you haven't then go to this link and see the demo:
https://www.w3schools.com/html/tryit.asp?filename=tryhtml_default
I've made many websites! Some with a website maker, others with HTML!
But please look at that. That explains it.

Powered by DjangoBB

Standard | Mobile