Rename script variable and all uses within custom block

image

I want to rename minutes to minute in a custom reporter that is very, very, very long (so it would take time and I might miss some instances of it)

Is there a way of doing this in a more reliable/faster way than doing them one at a time?

Right click (minutes) :: other reporter and click "Rename all...". Enter your new name, and all instances get insta-replaced.

PS: What're (the word "what're" is valid, it means "what are") you working on, just in case if it wasn't a secret?

This kind of defeats the purpose of a contraction. :~)

That doesn't work for me.

I tried renaming minutes to "tooty fruity" and it only seems to change the script variable definition - none of the other mentions get changed
image

image

That's cause "rename all" doesn't work very well in custom blocks. You may have to drag the script outside the block, then use "rename all".

Did you make sure to select "rename all" instead of "rename"?

Hi Simon, "rename all" should totally work! If it doesn't I'll consider it a bug. Can you share the project with me? Tnx.

Here is empty project with the block in it

Apolgies for it#s size - it was programmed very "industrially" :slight_smile: and has grown over the years :slight_smile:

https://snap.berkeley.edu/snap/snap.html#present:Username=cymplecy&ProjectName=timestamp

Note - if you try the block out - use UTC or manual offset to avoid problems in looking up local time via http call

I have found a workaround.

I imported the code to blocks lib
image

Extracted the script from within the reporter and encoded the blocks as text

Pasted result into text editor and then used that to search and replace minutes variable set/get mentions with minute

And then copied that back and used the parse code reporter to give me back the blocks.

Bit of a faff but it seems to have done the job.

Thanks, Simon. I'm glad you've found a way to rename the variable. That is an interestingly gargantuan function :D. But it also seems to trigger a problem with the "rename all" variable refactoring feature that I'll look into. Thanks!

As an aside, I came up with this little script to automate my workaround

And it works very nicely except when I try to replace the block definition with the converted script - for some reason the block header gets changed

I tried doing this on a simpler custom reporter and that worked but other custom reporters also fail

[edit] Jens has fixed this issue in the 10.1 dev version

Is the behavior similar to what I ran into here?

(I didn't realize how long ago I posted this, I thought it was this year, lol)

weird. :s

I have found that in large custom blocks, when you use "rename all" Snap! will lag and sometimes crash completely.

I think I've managed to make a custom block that will successfully rename any variable in another custom block - even huge ones like my datetime one :slight_smile:

costumeShape23Oct2024 script pic

I don't want people going out of their way to find cases where it doesn't work :slight_smile:
But if it fails for you while using it for real - let me know :slight_smile:
[edit] 23Oct2024 Updated the block to handle custom reporters that use the warp block

And to help me tidy up my big reporter - I've made this block to let me sort a script variables block

untitled script pic (45)

I've also come up with this reporter to merge several script variable blocks into one

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.