Define a Type

Start here all your tutorials for Truespace Worskpace Side.
Post Reply
Shell1850
Chief Petty Officer
Posts: 135
Joined: 21 May 2009, 21:44

Define a Type

Post by Shell1850 » 15 Sep 2011, 19:51

Jscript can group a group of variables into a type definition.

I created this simple program. It adds 3 numbers.


// create a type

function AddTheseNumbers(first,second,third) {
this.One = first;
this.Two = second;
this.Three = third;
}

function OnComputeOutputs(params)
{
var First = params.ConValue('First');
var Second = params.ConValue('Second');
var Third = params.ConValue('Third');

var NewList = new AddTheseNumbers(First, Second, Third);
var NewAdd = AddNumbers(NewList);

params.ConValue('AddResult') = NewAdd;
}

function AddNumbers(ListofNumbers)
{
return (ListofNumbers.One + ListofNumbers.Two + ListofNumbers.Three);
}
Attachments
Type Example.zip
(3.31 KiB) Downloaded 17 times

froo
Captain
Posts: 2552
Joined: 22 May 2009, 12:13

Re: Define a Type

Post by froo » 16 Sep 2011, 01:25

Interesting, Shell1850.

I have not looked at the jscript spec, so I'd like to know...
is the word 'this' a keyword in jscript? And if so, is it significant
in relation to how the data structure is instantiated?
In other words, can we use the word: 'that' in place of 'this'?
Or any other variable name for that matter, in your sample code?

Thanks

Froo

clintonman
Captain
Posts: 2242
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Define a Type

Post by clintonman » 16 Sep 2011, 01:32

Here's a link to a similar topic.
http://www.webbasedprogramming.com/Spec ... pt/ch4.htm" onclick="window.open(this.href);return false;
Clinton Reese

http://clintons3d.com

clintonman
Captain
Posts: 2242
Joined: 21 May 2009, 21:08
Type the number ten into the box: 0
Location: California
Contact:

Re: Define a Type

Post by clintonman » 16 Sep 2011, 01:38

froo wrote:Interesting, Shell1850.

I have not looked at the jscript spec, so I'd like to know...
is the word 'this' a keyword in jscript? And if so, is it significant
in relation to how the data structure is instantiated?
In other words, can we use the word: 'that' in place of 'this'?
Or any other variable name for that matter, in your sample code?

Thanks

Froo
Nope, "this" is a special keyword. From JScript docs, "Refers to the current object""The this keyword is typically used in object constructors to refer to the current object"
I think c or c++ has something similar and I know python also uses it.
Clinton Reese

http://clintons3d.com

froo
Captain
Posts: 2552
Joined: 22 May 2009, 12:13

Re: Define a Type

Post by froo » 16 Sep 2011, 02:09

Thanks clinton.
That's what I was suspecting. C++ uses it.

Post Reply