Defining Project Variables

In the Dynamo language guide it says a function does not need to take an argument and can return a fixed value. This seems like it could be a useful way to “hide” a lot of wires in a graph if there are variables up front that affect many things (unless I’m missing something). However, I cannot seem to get it to work (not much programming experience, but am trying to learn). Bottom definition is by the book. Top definition is my trying another way…

Function_no_arguments

Hey mate,

I’m not 100% sure as I’m also relatively new to this programming stuff too but my guess is that you need to call the function. The code block is only defining a function, the code blocks on the right need to call that function. So, in the bottom block, it has “x = Ht()” which is calling the function and assigning the result to the variable “x”. In the code blocks on the right, you need to do the same thing; call the function.

Cheers,

Jeremy.

1 Like

A few comments…

  1. Jeremy’s right. You’ll need to use Ht() , just Ht will not work.

 

  1. Each of the defined functions will have to have a unique name. You can’t have two functions named Ht

In your case the one code block is redundant as the functions in both blocks are exactly the same. x=Ht() in one of the code blocks is outside the curly braces and not part of the defined function.

The extents of the definition aren’t determined by the code block within which it is contained. You can define multiple functions within the same code block.

 

  1. Once you get familiar with Design Script you wouldn’t need to “hide” wires as your definition will have few or no wires to hide.

Gents,

Spot on! Was missing ( ). These defined functions are nice because they do not need to reside in a folder on your hard drive like custom nodes-- just open and go! Does anyone know if a function can be created that can return more than one value? Multiple values of different types (like custom nodes)?

Nick
Variables

Yes they can return multiple values.

20150927-1

1 Like

Understood, thank you Vikram for your help. :slight_smile:

Does your (and a few other ninjas on this site) extensive knowledge of code blocks come from past experience with design script? I recently found a couple designscript handouts (maybe outdated) that tell more than the primer currently does. I’m guessing there is lack of documentation on some functions in the primer since the program is still being worked out. I have been following this line of inquiry to essentially see if code blocks and nodes are interchangeable-- since nodes must be installed on all users machines wishing to work in the .dyn file(s), where as code blocks work when opened. Another motivation is the ability to gradually reduce “wires” on the canvas when cleaning up a definition as it is built.

http://aucache.autodesk.com/au2012/sessionsFiles/3286/5471/handout_3286_DesignScript_summary_user_manual.pdf

http://aucache.autodesk.com/au2012/sessionsFiles/3365/5474/handout_3365_DesignScript_summary.pdf

 

Again, I know time is precious so please don’t feel obligated to respond. Your responses have been a great help. :slight_smile:

Best regards,

nick

Nick, my knowledge of Design Script is certainly not extensive :slight_smile:

I have absolutely no prior experience in programming and I began exploring Design Script only after it was made part of Dynamo.

Almost all of what I’ve learnt is from the Dynamo language guide (the older version of it, actually) and from this community.

I am mostly interested in Dynamo as a design tool and most of my learning is a result of me looking for means to express design intent with code.

About a year ago, I decided to attempt to use code to conceive a competition entry using just code, based on available site/urban data. This is when I committed a lot of time and effort to Design Script (though, I’d started looking at Dynamo about two years ago).

On this forum, when I put my two bits in, every now and then, I’m not being altruist. More often than not, I don’t have a ready solution. I work on it and it’s one of the few ways by which I continue to discover and learn.

My learning process has been crude and disorganized, maybe inefficient and definitely incomplete, but I hope the insight helps.

 

Hi. What am I doing wrong here?

Others please chime in, but I don’t believe you can use a code block input to define a value within a defined function (unfortunately-- this is a huge wishlist item for me too!). As a result, when you call your function y(), your code block is attempting to return the x variable within your definition, but it doesn’t know what x is so it gives null.

Does anyone know how to use outside data within a function?

Mogiel,

Haha, just remembered I had this same problem a while back. The examples above in this conversation outline how to declare constants– ie values that never change throughout a script unless changed within the function definition.

The answer to your question is: You need to define the value as an input variable between the parentheses.

What you attempted is the same wish I had when I first tried: “Can I plug a wire into a codeblock and have it DRIVE a value within the original definition of a function?-- populating all instances of that function call with that value.” Would be useful, and am not sure why we can’t do this at present. Closest I could come was the third example in the image above – reference a defined constant from within another function definition. May be getting a bit convoluted at this point, but it’s all I could come up with.

I’ve been doing a little reading on C#, and this may be similar to the difference between public and private values within a class, but I can’t be sure.

original post: