Script variable from inside a custom block definition inside a c block

So I have a custom block with a c-shape command input. I also have another custom block that's supposed to go in there. I need to have a script variable in the c block and then use the other custom block. But I need to access the script variable from the definition of the inner custom block, WITHOUT using an input for it. I'm not really sure how I would do this, but if it's possible then it would make everything much easier

I think I have a working solution. Here's a link to the project:

Doesn't work if you rename the upvar :frowning:

I wanted to do something similar once and never managed to come up with a method that worked

Yeah. I provided an example where all the blocks use the name “upVar”. You would need to modify the (make list a value) block in your own project if you wanted to use it, and you would also need to change the value you put into the set () to () then () reporter from “upVar” to whatever the upvar is named now.

Do you want something like this?

untitled script pic (6)

Edit: wait, that's not what you want. You want to be able to access a script variable defined outside a custom block, but access it in a custom block. It's best practice to use an input for this. If you want the custom block to change the variable, then stick the variable inside a grey ring, then in the custom block, just run with inputs. This will explain it better.

Also, this isn't a text language that has everything in one script, and custom blocks (functions) are not defined inside another script, so accessing script variables in a custom block is something that just doesn't make sense for a block language.

but how would I access the 'a' variable?

this is what I want to do exactly:

(create new object with ((keys λ) :: custom) :: custom) :: control hat
script variables ((a) :: grey) ‍@addInput :: grey
set [a v] to (split ({script variables ((temp) :: grey) :: grey
set [temp v] to (list ‍@addInput :: list)} ‍@addInput :: grey) by [blocks v] :: operators)
add (split (keys) by [blocks v] :: operators) to (a)
add (split ({report (temp) :: control cap} ‍@addInput :: grey) by [blocks v] :: operators) to (a)
report (call (join input list: (a) :: operators) ‍@addInput :: control) :: control cap

{add ((key) :: custom) with value ((value) :: custom) :: custom} :: control hat
set (value) to key (key) in collection ‍[] :: custom // don't worry about what this block does, it just modifies the list input.
// the empty input should have the 'temp' var from the other block that I want to access

create new object with {
add [key] with value [value] :: custom
} :: custom reporter // supposed to be a c shape input

Could you try to explain what you would like the CREATE NEW OBJECT … block to do?
As of now I don’t have a clue :thinking:

it should report the 'temp' variable as a table that's 2 wide. Each row is a key-value pair specified by the add key with value blocks that go in the reporter c-shape.

If you're just trying to create a dictionary, then you don't need to have a custom block access a script variable. You can have a list as an input, modify it, and it'll modify the original list.

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