How Do You "Broadcast Messages?" Edit: Sorry, for the mistake I'm using Wick Editor 1.19.3

Fill this out this info to make it easier for the community to help you! If you don’t fill out this information, your post may be deleted or removed.

What Wick Editor Version are you using?
Ex. 1.18. You can find this on the splash screen when the editor opens.

I’m using Version 1.18 for Wick Editor.

Describe the Problem
What issues are you having in the Wick Editor?

For example, if I pushed a settings button for brightness, it would change the brightness right? How could I apply that to Wick Editor? For example, if I held down the down arrow button, the project would change brightness the longer I held it. Or maybe if I clicked a button, it could perhaps change the look of a character, like if the character had a sombrero on him, then he would have a top-hat if I clicked that button.

If you don’t want to read that long paragraph, maybe I’ll just explain it in some code that might be similar to Wick that I made up??

if “Button” clicked:

change costume by 1

end
What have you tried so far?
Have you attempted anything to fix the problem? Let us know!

I really haven’t because I don’t really know what to do. Sorry I’m quite new to Wick.

Thanks, and sorry for everything.

Welcome to the wick forums, glad you’re here! :partying_face: :man_dancing:t4:

So if you want to change brightness, create a new layer and drag it to the top, and in a new frame in the layer, put a black box over your project.
Turn the box into a clip and set its opacity to 0 using the slider.
Create a keypressed script, and enter this code

if (key === “left” ) { //if the left arrow key is pressed
this.opacity+=0.05 //Increase opacity of object
}
if (key === “right” ) { //if the right arrow key is pressed
this.opacity-=0.05 //Decrease opacity of object
}

Then, on the layer, press the lock, and extend the frame to the length of your project’s timeline.

If you’re having trouble, here’s a template, the top layer is the opacity thing
My Project5-24-2021_8-41-44.wick (3.2 KB)

If you want to reference a clip, like change it’s opacity or xy position, you can turn it into a clip and give it a name, then elsewhere in the project you can use clipname.opacity+=0.1 to increase its opacity by 0.1

you can also reference a clip inside itself by using this. or something inside it’s own clip by using this.clipname

You can also use project. to interface with the main project and/or its timeline.

1 Like

hi, there aren’t any languages i’ve seen with built-in support for message passing/broadcasts like in Scratch… maybe Logo I think? (I know nothing about Logo)

you could try programming this on your own, but it’d be much easier to just use global variables or change the variable of some clip.

you could make something like project.brightness -= 0.1 run on a keydown script. then have code in the update script of some clip set some value according to the project.brightness variable.

or you could have a reference to some clip, then on the keydown script run

clip.brightness -= 0.1;
clip.functionToUpdateSomethingBasedOnBrightness();

hope this helped

you could create your own broadcast code, something like this.

project.broadcasts = [];
function broadcast(str) {
    // add str to broadcasts
}
function recieve(str) {
    // if broadcasts has str, return true and delete str from broadcasts, otherwise return false
}

i’m no pro at scratch, but i think this is how it sorta works…

actually i think recieve doesn’t delete broadcasts, broadcasts just deletes everything inside it every cycle. or something.

i’m not sure how that would work… do you run the receive function on every frame? i feel like that would be unnecessary. how i would do it is, it runs the code only when the broadcast is broadcasted, by putting the function you want to run in a list, and running every function in the list when the broadcast is broadcasted.

var broadcasts = {};
// its keys are broadcast names
// and the values are lists of functions that should run on a certain broadcast

// this is the receiver function, it works like addEventListener
project.onMessage = function(name, f, runner) {
  // if the runner of this function isn't specified, it defaults to project
  if (!runner) runner = project;
  // if key name doesn't exist, then create an array at the key
  if (!(name in broadcasts)) broadcasts[name] = [];
  // add the function to the list
  broadcasts[name].push([f, runner]);
};

// this is the function that sends broadcasts
project.broadcast = function(name) {
  // if this name exists in broadcasts?
  if (name in broadcasts) {
    // go through every item in the receiver list
    for (let dat of broadcasts[name]) {
      // run the function with the runner as the this value
      dat[0].call(dat[1]);
    }
  }
};
1 Like