Assigning value to a struct in JavaScript.

Hello,

as I understand, it is possible simulate behavior of struct, by using this construct:

private class StructName extends System.ValueType

I would like to use a struct in my case, but what I came across is that I can’t change value of the struct, with this kind of a code:

public var structure : StructName;

private function UpdateValues (tmpStruct : StructName) {
  tmpStruct.floatValue = 10.0;
}

public function Start () {
  UpdateValues (structure);
}

while this does work

public var structure : StructName;

private function UpdateValues () {
  structure.floatValue = 10.0;
}

public function Start () {
  UpdateValues ();
}

Why is that so?

Ah, sorry, here’s info:

That is a struct, not a simulation…structs are value types. Anyway, both of your code examples work; what are you expecting?

–Eric

Structs are passed by value so when you include it as an argument to a method you’re passing a copy, not the original.

1 Like