Class Definition Error

I’m trying to build a class, but i get an error stating

Error: ‘;’ is expected

class Profile
{
	department = " ";
	subDepartment = " ";
	name = " ";
	count = 0;
	area = 0.0;
	comments = " ";
	guidelines = " ";
	id = " ";

	constructor ByValues (d, sD, n, ct, a, cm, g, id)
	{
		this.department = d;
		this.subDepartment = sD
		this.name = n;
		this.count = ct;
		this.area = a;
		this.comments = cm;
		this.guideline = g;
		this.id = id;
	}
};

I copied some code from the spec document and that fails in the same way. I feel like there’s something really basic i’m missing here, but am having trouble finding other tutorials

class Point2D
{
	x = 0;
	y = 0;

	constructor ByCoordinates (x,y)
	{
		this.x = x;
		this.y = y;
	}
};

It seems like you are missing a ; after this.subDepartment = Sd

hmm. yep. this is definitely true. i added the ; and it still gives the same error

DesignScript is not exactly the same as C#, it is another language.

What are you trying to create exactly? PS: I don’t know what you are referring to with “class”

You cannot do this in a Code Block
With a few changes to your code, possible in a file with a .ds extension

class Profile
{
	department;
	subDepartment;
	name;
	count;
	area;
	comments;
	guidelines;
	id;

	constructor ByValues (d, sD, n, ct, a, cm, g, id)
	{
		this.department = d;
		this.subDepartment = sD;
		this.name = n;
		this.count = ct;
		this.area = a;
		this.comments = cm;
		this.guideline = g;
		this.id = id;
	}
}

On importing the .ds file into Dynamo, nodes are created.
However, this doesn’t work too well :smirk:

class

4 Likes

Hello, and thank you for sharing knowledge, the incoming are all string, in this situation?

Thanks
Cordially
christian.stan

1 Like

ah. i overlooked the line in the Design Script Guide: just like you said.

Note:​ Classes can only be declared in DesignScript script files or files that have a .DS extension. Class
declarations are not allowed in code block nodes in Dynamo. DS files can be imported into a Dynamo
session to be consumed as nodes.

i was trying to streamline the management of a ‘profile’ as part of a space planning graph. currently, i’m using a dictionary, but thought it would be nicer to just be able to use . access notation. Also recognize that classes are something that i don’t really understand to well so i thought this might be the right situation to use it.