Discuss Scratch

tugael06
Scratcher
44 posts

Creating extensions for Scratch 3.0

Sorry for making blocks
I'll be here in tommorow ok?
tugael06
Scratcher
44 posts

Creating extensions for Scratch 3.0


I'M SO SORRY
tugael06
Scratcher
44 posts

Creating extensions for Scratch 3.0

PLEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEASE FORGIVE ME
PLEASE I'M A SCRATCHER OK?
OK
OK
OK
OK
OK
OK
OK
OK???
GEEZ BIRDIE
dinnerbone78780
Scratcher
8 posts

Creating extensions for Scratch 3.0

im getting a Syntax error when doing the first step please help

Sheep_maker wrote:

I've updated my mod to the latest version of 3.0.
https://sheeptester.github.io/scratch-gui/?url=https://sheeptester.github.io/javascripts/utilities.js

I deleted my old mod so I had to remake the changes, and so now you can't save/load projects using URL-loaded extensions with my mod. oof

However, it seems they've fixed the extensions running the blocks some time ago, so the blocks in the extensions can now be used! Reporters now also get their own watchers (but they don't seem to use the extension's block colours) yay

I made a shallow clone of the Scratch GUI, so I can't commit my changes to Github very easily; instead, I'll just list them here.

src/lib/libraries/extensions/index.jsx, before line 29 I added:
    {
        name: (
            <FormattedMessage
                defaultMessage="Choose an extension"
                description="Name for the custom extension selector"
                id="gui.extension.custom.name"
            />
        ),
        iconURL: customImage,
        insetIconURL: customInsetImage,
        description: (
            <FormattedMessage
                defaultMessage="For developers"
                description="Description for the custom extension selector"
                id="gui.extension.custom.description"
            />
        ),
        featured: true
    },
This adds the “Choose an extension” button to the extensions library; customImage and customInsetImage are the icons, which you can import like so:
import customImage from './custom.png';
import customInsetImage from './custom-small.svg';

src/containers/extension-library.jsx, lines 34-39 were changed to:
let id = item.extensionId;
let url = item.extensionURL ? item.extensionURL : id;
if (!item.disabled && !id) {
    // eslint-disable-next-line no-alert
    url = prompt(this.props.intl.formatMessage(messages.extensionUrl));
    if (url) {
       id = url;
    }
}
This allows custom URLs to actually be used when loading them.

src/lib/vm-manager-hoc.jsx, after line 30 I added:
            if (window.location.search.indexOf('url=') !== -1) {
                const extensionURL = window.location.search.match(/url=(https?:\/\/[\w.\/-]+)/)[1];
                this.props.vm.extensionManager.loadExtensionURL(extensionURL);
            }
This loads the extension from the URL. I'm not sure if this is the best place to put this, but it works

define never
stop [scratch v]
ExpungleCat2023
Scratcher
12 posts

Creating extensions for Scratch 3.0

supercatmaker2 wrote:

class NitroBlock {
getInfo() {
return {
"id": "NitroBlock",
"name": "NitroBlock",
"blocks": [{
"opcode": "substringy",
"blockType": "reporter",
"text": "letters [num1] through [num2] of [string]",
"arguments": {
"num1": {
"type": "number",
"defaultValue": "2"
},
"num2": {
"type": "number",
"defaultValue": "5"
},
"string": {
"type": "string",
"defaultValue": "hello world"
}
}
},
}],
"menus": { //we will get back to this in a later tutorial
}
};
substringy({num1, num2, string}) {
return string.substring(num1 - 1, num2);
};
}

That makes it much easier to understand

My name is Maxx. I was the loyal “pet” cat to Expunged, but I ran away. Want to join the Expunged Empire? Sign up here: https://scratch.mit.edu/projects/822961685
add [Expunged] to [Peeps i ran away from v]
paulGaming2
Scratcher
6 posts

Creating extensions for Scratch 3.0

Maybe command blocks?
Start Command: [/show sprite:Sprite1:] Then: [end/]

Last edited by paulGaming2 (March 28, 2024 18:33:57)

seejc
Scratcher
3 posts

Creating extensions for Scratch 3.0

using System.Collections;
using System.Collections.Generic;
using ScratchEngine;


public class FPSController : MonoBehaviour
{
public Camera playerCamera;
public float walkSpeed = 6f;
public float runSpeed = 12f;
public float jumpPower = 7f;
public float gravity = 10f;


public float lookSpeed = 2f;
public float lookXLimit = 45f;


Vector3 moveDirection = Vector3.zero;
float rotationX = 0;

public bool canMove = true;


CharacterController characterController;
void Start()
{
characterController = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}

void Update()
{

#region Handles Movment
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 right = transform.TransformDirection(Vector3.right);

// Press Left Shift to run
bool isRunning = Input.GetKey(KeyCode.LeftShift);
float curSpeedX = canMove ? (isRunning ? runSpeed : walkSpeed) * Input.GetAxis(“Vertical”) : 0;
float curSpeedY = canMove ? (isRunning ? runSpeed : walkSpeed) * Input.GetAxis(“Horizontal”) : 0;
float movementDirectionY = moveDirection.y;
moveDirection = (forward * curSpeedX) + (right * curSpeedY);

#endregion

#region Handles Jumping
if (Input.GetButton(“Jump”) && canMove && characterController.isGrounded)
{
moveDirection.y = jumpPower;
}
else
{
moveDirection.y = movementDirectionY;
}

if (!characterController.isGrounded)
{
moveDirection.y -= gravity * Time.deltaTime;
}

#endregion

#region Handles Rotation
characterController.Move(moveDirection * Time.deltaTime);

if (canMove)
{
rotationX += -Input.GetAxis(“Mouse Y”) * lookSpeed;
rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
transform.rotation *= Quaternion.Euler(0, Input.GetAxis(“Mouse X”) * lookSpeed, 0);
}

#endregion
}
}

Last edited by seejc (April 1, 2024 15:36:49)

archiearc
Scratcher
4 posts

Creating extensions for Scratch 3.0

tell scratch to make an extension creator in project editor
Casimary
Scratcher
2 posts

Creating extensions for Scratch 3.0

NitroCipher wrote:

Creating extensions for Scratch 3.0


There is now official documentation regarding extensions!, but feel free to use this post to get you started


You'll want to start off by creating your extension's class, and register the extension - In my case, this would be ‘NitroBlock’

class NitroBlock { //In both instances, NitroBlock will be the name in both instances
}
Scratch.extensions.register(new NitroBlock());

Next, we will be constructing block and menu definitions - We will continue to use ‘NitroBlock’ through this tutorial
getInfo() {
    return {
        "id": "NitroBlock",
        "name": "NitroBlock",
        "blocks": [
        ],
        "menus": { //we will get back to this in a later tutorial
        }
    };
}

We are going to take a look at how blocks are constructed

For those of you that are familiar with extensions for Scratch 2.0, we will start off with this: - If not, you can ignore this
['r', 'letters %n through %n of %s', 'substringy', '2', '5', 'hello world']
//breakdown below:
['r' = block type, 'letters %n through %n of %s' = block text, 'substringy' = block ID/opcode]

{
    "opcode": "substringy", //This will be the ID code for the block
    "blockType": "reporter", //This can either be Boolean, reporter, command, or hat
    "text": "letters [num1] through [num2] of [string]", //This is the block text, and how it will display in the Scratch interface
    "arguments": { //Arguments are the input fields in the block. In the block text, place arguments in square brackets with the corresponding ID 
        "num1": { //This is the ID for your argument
            "type": "number", //This can be either Boolean, number, or string
            "defaultValue": "2" //This is the default text that will appear in the input field, you can leave this blank if you wish
        },
        "num2": {
            "type": "number",
            "defaultValue": "5"
        },
        "string": {
            "type": "string",
            "defaultValue": "hello world"
        }
    }
},

We will put this newly constructed code into the blocks object above - My code will now look like this
class NitroBlock {
    getInfo() {
        return {
            "id": "NitroBlock",
            "name": "NitroBlock",
            "blocks": [{
                    "opcode": "substringy",
                    "blockType": "reporter",
                    "text": "letters [num1] through [num2] of [string]",
                    "arguments": {
                        "num1": {
                            "type": "number",
                            "defaultValue": "2"
                        },
                        "num2": {
                            "type": "number",
                            "defaultValue": "5"
                        },
                        "string": {
                            "type": "string",
                            "defaultValue": "hello world"
                        }
                    }
                },
            }],
        "menus": { //we will get back to this in a later tutorial
        }
    };
}
Scratch.extensions.register(new NitroBlock());

Next we come to the most important part, the code that actually runs the blocks! - I am keeping this short and simple for tutorial's sake.
//Make sure you name this function with with the proper ID for the block you defined above
substringy({num1, num2, string}) { //these names will match the argument names you used earlier, and will be used as the variables in your code
    //this code can be anything you want
    return string.substring(num1 - 1, num2);  //for reporters and Boolean blocks the important thing is to use 'return' to get the value back into Scratch.
}

Place this new code below your getInfo() function
class NitroBlock {
    getInfo() {
        return {
            "id": "NitroBlock",
            "name": "NitroBlock",
            "blocks": [{
                    "opcode": "substringy",
                    "blockType": "reporter",
                    "text": "letters [num1] through [num2] of [string]",
                    "arguments": {
                        "num1": {
                            "type": "number",
                            "defaultValue": "2"
                        },
                        "num2": {
                            "type": "number",
                            "defaultValue": "5"
                        },
                        "string": {
                            "type": "string",
                            "defaultValue": "hello world"
                        }
                    }
                },
            }],
        "menus": { //we will get back to this in a later tutorial
        }
    };
    substringy({num1, num2, string}) {
        return string.substring(num1 - 1, num2);
    };
}

Save this code to your computer as a js file, in my case it is NitroBlock_3.js

Congratz, you now have your extension code created!!
You can use this tutorial to add it your own personal copy of scratch
Or, you can host the extension with gh-pages, and go here to test it
(provide your own url, don't use mine)

Here is the archived copy of my original post
I don't even understand any of Javascript
Casimary
Scratcher
2 posts

Creating extensions for Scratch 3.0

archiearc wrote:

tell scratch to make an extension creator in project editor
YEEEEEEEEEES!!!!!!!!!!! PLEASE!!!!!
Charlieonthego
Scratcher
20 posts

Creating extensions for Scratch 3.0

create [new extension v] :: extension
comment [automatic timer for sure when it is run v] :: custom
when green flag clicked
make [pen extension v] :: control
turn [turbo mode v] on
make intro :: operators
PLEASE GET THE EXTENSION

- KlaskyCsupoLogos2641 alt
Charlieonthego
Scratcher
20 posts

Creating extensions for Scratch 3.0

seejc wrote:

using System.Collections;
using System.Collections.Generic;
using ScratchEngine;


public class FPSController : MonoBehaviour
{
public Camera playerCamera;
public float walkSpeed = 6f;
public float runSpeed = 12f;
public float jumpPower = 7f;
public float gravity = 10f;


public float lookSpeed = 2f;
public float lookXLimit = 45f;


Vector3 moveDirection = Vector3.zero;
float rotationX = 0;

public bool canMove = true;


CharacterController characterController;
void Start()
{
characterController = GetComponent<CharacterController>();
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}

void Update()
{

#region Handles Movment
Vector3 forward = transform.TransformDirection(Vector3.forward);
Vector3 right = transform.TransformDirection(Vector3.right);

// Press Left Shift to run
bool isRunning = Input.GetKey(KeyCode.LeftShift);
float curSpeedX = canMove ? (isRunning ? runSpeed : walkSpeed) * Input.GetAxis(“Vertical”) : 0;
float curSpeedY = canMove ? (isRunning ? runSpeed : walkSpeed) * Input.GetAxis(“Horizontal”) : 0;
float movementDirectionY = moveDirection.y;
moveDirection = (forward * curSpeedX) + (right * curSpeedY);

#endregion

#region Handles Jumping
if (Input.GetButton(“Jump”) && canMove && characterController.isGrounded)
{
moveDirection.y = jumpPower;
}
else
{
moveDirection.y = movementDirectionY;
}

if (!characterController.isGrounded)
{
moveDirection.y -= gravity * Time.deltaTime;
}

#endregion

#region Handles Rotation
characterController.Move(moveDirection * Time.deltaTime);

if (canMove)
{
rotationX += -Input.GetAxis(“Mouse Y”) * lookSpeed;
rotationX = Mathf.Clamp(rotationX, -lookXLimit, lookXLimit);
playerCamera.transform.localRotation = Quaternion.Euler(rotationX, 0, 0);
transform.rotation *= Quaternion.Euler(0, Input.GetAxis(“Mouse X”) * lookSpeed, 0);
}

#endregion
}
}
I think you are trying to get C# instead of JavaScript
ggGamerpoke
Scratcher
60 posts

Creating extensions for Scratch 3.0

maybe a 3D exstention [someting like raycasting 3D or normal 3D ]

Last edited by ggGamerpoke (May 5, 2024 07:08:54)


removed–please don't share contact information
Charlieonthego
Scratcher
20 posts

Creating extensions for Scratch 3.0

class NitroBlock {
getInfo() {
return {
"id": "NitroBlock",
"name": "NitroBlock",
"blocks": [{
"opcode": "substringy",
"blockType": "reporter",
"text": "letters [num1] through [num2] of [string]",
"arguments": {
"num1": {
"type": "number",
"defaultValue": "2"
},
"num2": {
"type": "number",
"defaultValue": "5"
},
"string": {
"type": "string",
"defaultValue": "hello world"
}
}
},
}],
"menus": { //we will get back to this in a later tutorial
}
};
substringy({num1, num2, string}) {
return string.substring(num1 - 1, num2);
};
}
SuperlabProductions
Scratcher
2 posts

Creating extensions for Scratch 3.0

Ooga booga
georgehmiller10
Scratcher
5 posts

Creating extensions for Scratch 3.0

How do you get extensions anyway???

georgehmiller10

when green flag clicked
say [georgehmiller10]
randomduck42
Scratcher
13 posts

Creating extensions for Scratch 3.0

im using the Scratch Addo*gets banned*
Charlieonthego
Scratcher
20 posts

Creating extensions for Scratch 3.0

or just use dev-turbobuilder.vercel.app

Last edited by Charlieonthego (May 20, 2024 19:15:56)

THE_diamond_2021cat
Scratcher
22 posts

Creating extensions for Scratch 3.0

randomduck42 wrote:

im using the Scratch Addo*gets banned*
same lol. everything on my end is G R E E N because i want it to be!
define also all the forum blocks are 3.0 blocks on my end

꧁•⊹٭DiamondCat٭⊹•꧂
julmik6478
Scratcher
100+ posts

Creating extensions for Scratch 3.0

archiearc wrote:

tell scratch to make an extension creator in project editor
You can use extension creators.


Support the suggestion HERE by adding this button to your signature

My social media:
youtube
snail ide
planet minecraft
mcreator
electramod

Powered by DjangoBB