If I have a set of vars with any kind of values t1=10, t2=true, t3=abc,
is there a way to have reporter function that will return the value of the var if I input the name of the var "in text" into the function.
eg:
reporter function (t1) <<< t1 is in text format, not the brown var name icon
returns 10
Or alternatively, is there a way all the vars of the program can be accessed in a "sensing reporter" type function; just like "my costumes", "my clones", "my ______", etc
I need to use these vars as codes in a project embedded in text. Even though I know it would be easier to use a list, it will not suit me for practical reasons.
Thx.
@ donotforgetmycode_sn
I am going to play with this. See if I can make it work.
It is simple, but creates a step of modifying the dictionary to synch with the vars.
@ jguille2
Sorry Joan, I am lost trying to understand what you mean.
Is the call block supposed to be used "with inputs t1 t2 t3" ?
And having nothing selected in the reporter block " __ of Sprite" produces an error.
That's not a dictionary. Dictionary is built into javascript, and should be built in to Snap! It has constant time lookup.
use ((name) of (my [self v])) where name is a reporter, such as a custom block argument or a one input join.
And it works great for both global and local vars.
However, if I use this within a MAP block within my custom block, then none of the custom block parameters or the script vars declared within the custom block are reachable. Outside the MAP, all is fine!
Does MAP create its own realm somehow?
And how does one use the parameters of the custom block in a MAP within the block via this method?
@jens
I know you are busy with the rewrite and I am sorry to bother you.
As an answer to the last reply, the example you provided are placed on coding area and they work the same with me.
However, my example is using the "value of __" JS code you provided in my custom block. There, neither script vars, nor the custom block parameters are accessible. Of course I might be doing something wrong. But, given that the same code works when I take it out of my custom block and place it on the coding area, there must be another issue.
Here again is my custom block:
My objective is:
access custom block parameters t1 and t2 by name
access custom block script variables m1 etc by name
As I said above, this works on the coding page without the custom block header, but not under my custom block definition.
Here is a trace run (with ERROR):
both JS calls (outside the MAP, and inside the MAP) give errors.
Same code on coding page without the custom block header (NO ERROR):
As far as why am I doing this:
I have pieces of text that have embedded formatting codes, eg: t1, t2, t3, c1, c2, c3, etc. that have a prefix character to tell me they are format codes (eg: ~).
I am using the MULTILINE text block to input these, then SPLIT to turn them into a list by LINE, then MAP to process each line.
On each line, as I encounter the codes mentioned, I look up the values by name (since they are in text format) that correspond to them and action it accordingly.
The example I have provided above is not the real code, but just an example to demo the problem encountered. So it probably makes no sense.
Anyway, many thanks for your attention in spite of your busy schedule.