Confused about "Broadcast"vs "Variable" use

We are confused about the Broadcast and the Variable function.
Is the “Broadcast” like a Call function in C language?i.e. Does is it call the “When” function.?
So would the Variable do the same thing e.g. Variable named “LiftUp” is placed in code and there is a “When LiftUp” function with “Forward 45 deg”. Does this mean the “When LiftUp” is called by the “Variable LiftUp” and the bot will move forward 45 deg?
Sorry if confusing. Will try to post pic of some code to explain this. We aren’t at our bot now to test this. Just programming.
Thanks.

9344c74e00a2b4949e924ea814b98c4c.jpg

391a45ecc0e7f6b19695770979e4a94a.jpg

aa7249f886e5c0b1cace443304c19a18.jpg

Hmmm. I really do want to help you…

Therefore, I have tried to answer your questions as clearly as possible below. Yes, it’s long. Feel free to skip the entire explanation :slight_smile:

Short reply:

Perhaps we should just focus on your goal. What is this code supposed to do?

I am also curious as to why you set velocity and power after your motor has already completed its motion. In this order, these new values will only take effect the next time your motor is activated. Perhaps you intended to set the values before the first action was completed?

Long explanation:

Broadcasts are “kind of similar” to a call. A call is meant to limit redundancy in a program. Calls activate a named section of code that is usually repeated often or triggered by multiple events. By calling the same bit of code over and over with a single call command from anywhere in a program, that section of code only needs to appear once in the entire code. Not only is this efficient because it makes the code shorter (one call can activate 1000s of lines of code), when changes are necessary, they only need to be made in that one section of code. (Versus duplicating that code over and over and then having to search through and edit every instance independently.)

Broadcasts are the other side of that coin. They send out one trigger that can activate multiple sections of code simultaneously. Three motors can all listen for the same broadcast and each carry out a specific set of instructions when that same signal is sent out. Note that each motor’s code is independent of the others, and they can all do very different things when the same broadcast is sent out. This is also efficient because all three sets of code can be activated with a single command.

A variable is a stored number. Setting a variable only changes the value of that stored number, it does not send out a signal per say. Instead, it is a value visible to all your code.

If you were doing sales calculations, you would need to add sales tax. Sales tax is a variable. You can set it to 5 petcent and write formulas that automatically add 5 petcent sales tax to the cost of an item. When the tax rate changes, say from 5 to 6 percent, you would change this variable in one place, and all your future sales will reference this new stored value and add 6 percent instead of 5.

In the short answer. We thought the “When LiftUp” was the first part of the function i.e. "When LiftUp"Set velocity and power max. Isn’t the "When"statement the start of your function?
If it is not then where do we do the “When LiftUp” function?

Great explanation in the “Long Answer”!
Thanks.

Just wish to help.
Yes, the When starts that bit if code and it goes in order from top to bottom. I was referring to your when lift degrees above fence code.

When we get to the hex balls -closeclaw-lift to raise off the post-hold power 100% -velocity 75

FYI: The 5th graders that I work with and I don’t actually compete. Instead, we design and solve our own student- and teacher-created challenges. So, I am unsure of the specifics of this challenge.

However, if you look at the code I posted for our “there and back again” challenge in the other thread, you can see one example of how to use a variable change to trigger a section of code. A broadcast will also work; I just prefer variable changes as event triggers.

Getting late here. I’ll see how busy I get tomorrow…

I keep one standard clawbot in my collection of bots at all times. Maybe I can post a fragment of code (the way I would code it) to close the claw and then lift (and hold) with the values you specify above using the basic clawbot. (For now, I can just guess on the degrees of rotation and you can change them to fit your need.)

Also, I have the other screen shots you posted, but can you upload your complete code as a file attachment? It would make this a lot faster!

Just to confirm, this portion of the code is for an autonomous challenge, correct?