So, I have a bunch of questions about how in the world some of the library custom blocks do and how they work. Would anyone be willing to answer some questions I have about them? I'll start with this one: What do all of the blocks in the "web services access (https)" library do? How do they work, and how do I use them? What are they even used for?
- The
[] url: [] send: [] headers: []
block is the same as the URL block, just upgraded. The first input tells to get, post, put, or delete on a request. You're likely going to use GET. The second input is the URL to request. You can find many API's online in the intermet. The rest of the inputs allow you to know what to send and what are the headers. - The
current location
block reports your location in latitude and longitude, which can be useful for map projects. listify
converts JSON into lists. Try{"a": 1, "b": 2}
.value at key [] of []
gets the value of a key in a list. Try{"a": 1, "b": 2}
and get the value of "a" and get 1.key [] value []
could be useful to make a JSON for sending headers.
In short, the web services library is used for making http(s) requests to apis. You're most likely never gonna use it, unless you need to use some api, as well as sending data in the request outside the url (if it's just a simple GET
request with no headers/data, you can just use the (url [])
block).
So basically it does a whole lot of stuff that I don't understand at all XD Okay.
Okay.
What about the "Iteration, composition" library? I hardly understand some of the regular control blocks, let alone these extra complicated ones.
This is quite complicated for me, but I'll answer as best as I can.
-
catch [] []
enables thethrow
block to execute, and when executed with the same tag as thecatch
block, will jump/skip to after thecatch
block. -
throw []
allows early exit from a script. It will cause to jump/skip to after thecatch
block if it's the same as thecatch
block. -
The reporter version of
catch
enables the two-inputthrow
block to execute, and when executed, returns the value instantly. -
The two-input
throw
block when executed, will return the value from the reporter version ofcatch
. -
if [] do [] and pause all
is the same as theif
block, except that when the condition is true and the statements are done, will pause the project, could be useful for debugging. -
ignore []
does nothing, could be useful for reporters and you don't care about the return value. -
cascade [] times [] [] []
returns the value called multiple times. The first input allows you to choose how many times you'd like to iterate. The second input allows you to choose an operation, like(3) + ()
. The third input allows you to choose an initial value. The fourth input is an upvar that indicates the nth cascade. For example,cascade [3] times [(3) + ()] [5] [#]
returns14
. -
cascade until
is returns the value called multiple times. The first input chooses the condition when it will stop iterating. The second input allows you to choose an operation. The third input allows you to choose an initial value. The fourth input is an upvar that indicates the nth cascade. -
compose
returns the functionx |-> f(g(x))
, where f and g are the two inputs. -
repeat [] until []
is the same asrepeat until
, except that it runs the command at least once. -
repeat [] while []
is the same asrepeat until
, except that it runs the command at least once and checks until the condition is false. -
repeat while
is the same asrepeat until
, except that it checks until the condition is false. -
The repeat block with an upvar is the same as the repeat block. The upvar returns the nth loop.
-
The for block with step is the same as the generic for block, except that it allows you to choose how much it will increase/decrease. A step of 3 inrceases 3-by-3.
-
let () be [] in loop
allows you to define a variable inside a loop. You can drag the upvar to inside the loop to simulate data inside them.
Fun fact, these are the only custom blocks that have a hardcoded (image) help dialog in snap (the help dialog was made before adding a comment to a block definition created a help dialog).
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.