Report the name of a variable reporter

Is it possible to obtain both the actual name of a variable as well as its value?
e.g a working version of this dummy one

image

You could do it the other way; take a text string as input and use the variables library to find the value of the variable with that name.

But (channeling Jens) if you want to do that, you're probably attacking your project in a way that works against how the language works, and you should consider using a dictionary instead of messing with variables.

I know what you mean and normally you'd be 100% right :slight_smile:

What I'm trying to do is emulate one of Scratch 1.4 great features - sending any variable values out on on a TCP port as a message like
sensor-update "foo" 45
which sends the name of the variable, foo, that's changed and its value

I'm doing this via http get requests instead of TCP messages and that's working fine to simulate the behaviour of broadcast blocks but I'd love to be able to do the same for variables

So I want a programmer to able to use my library with a custom set block and drop any variable into it and get it to send the name and its value out in one message
e.g
image

Could you paste the xml code for that please? as having trouble replicating it.

<blocks app="Snap! 6, https://snap.berkeley.edu" version="1"><block-definition s="get name of %&apos;var&apos;" type="reporter" category="other"><header></header><code></code><translations></translations><inputs><input type="%anyUE"></input></inputs><script><block s="doReport"><block s="reportListItem"><l>1</l><block s="reportTextSplit"><block s="reportListItem"><l>2</l><block s="reportTextSplit"><block s="reportJoinWords"><list><block var="var"/></list></block><l>("</l></block></block><l>..."</l></block></block></block></script></block-definition></blocks>

:smiley: :smiley: :smiley:

Just what I was after - thank you very much :slight_smile:

image

For any others looking at this - the basic "trick" is to set the var to unevaluated so it just returns the object and not its value - the join then converts it to an easy to parse string

image

image

And then, of course, it turns out @bh was right in the first place - I was attacking it wrong :slight_smile:

I don't really want/need to drop the variable reporter itself into the block - all I need t do is use the menu option and select the variables I'm after :slight_smile:

image

image

And achieve my ultimate aim to set the variable value and then send it out to my python webserver :slight_smile:
image

But it was a great learning exercise :slight_smile:

This is very clever. I actually thought of JOIN and then when I saw what it reported I got discouraged, but SPLIT makes scraping the result pretty easy.

And @cymplecy thinking of the variables menu, which totally skipped my mind, is also very clever. I've learned a lot from this thread!

Hey, are you guys coming to Snap!Con?

I certainly am - very excited - never been to California before :slight_smile:

And you get a tour of the Berkeley campus, in Minecraft. :~)

I wish I could see the tour in minecraft, oh, and I'll be gone next week, so I won't be able to go to snapcon2020

But the conference is this week. Starts tomorrow, 8am California time, or 15:00Z. Be there or be square!

ok, well, my mom would make me get off the computer at that time anyway (because she thinks I'm on the computer too long). I would love to go (even though I might just start working on a scratch project that I've been working on for almost a year). If you record it I may watch the recording and decide if I want to do it next time, and I won't be able to go on sunday. I also think the forum's enough for me.

We are indeed recording the sessions. But the best part of a conference is always the side conversations in the hallways.

lol, I really wish I could go.

Not pushing or anything, but you could explain to your mom that this is a serious annual academic conference, not you playing games, or even you coding.

No

:~(