Page 1 of 1

Create class - type objects

PostPosted: Thu Mar 17, 2016 4:44 pm
by Kilinich
I've just discover new feature ! :o
Looking into thyme config I saw strange string:

Code: Select all
math.vec := alloc;


That "alloc" is a stub for class-type object so you can create your own classes like obj.some.property.tree = true
Unfortunatly, Algodoo could not serialize and save it, so you should be aware, all internal objects will be stored (and ruin) in root scope.
That means you can't save it with scene and should only use it as temporary structure (or re-create it every time onSpawn) :(

Example:

Code: Select all
Scene.AddBox({
  pos := [0,0];
  onSpawn := (e) => {
    e.this.aTree := alloc;
    aTree.root := 1;
    aTree.branch := 2;
    aTree.leaf := 10
  }
})

Re: Create class - type objects

PostPosted: Sat Mar 19, 2016 5:45 pm
by pnvv
You're a fokn genius.

I wonder what exactly this could be used for? 8-)

Re: Create class - type objects

PostPosted: Fri Mar 25, 2016 9:11 am
by Kilinich
1st good implementation - list with direct element write access :thumbup:

Code: Select all
scene.my.array = [1,2,3,4,5,6,7];
scene.my.xArray := {
   a := [];
   for (7, (i) => {
      var := alloc;
      var.val := scene.my.array(i);
      a = a ++ [var]
   })
}();
print((scene.my.xArray(3)).val);
(scene.my.xArray(3)).val = 13;
print((scene.my.xArray(3)).val);


Too bad it's became usual list after close/open scene.
Well, it could be solved with a 1-time run spawn script, to convert it back.

Re: Create class - type objects

PostPosted: Fri Mar 25, 2016 9:23 am
by Xray
Great find! I will experiment with it to find out if it has any serious bugs or other issues. This will be very useful in scenes that use arrays.

Thanks! :clap:

Re: Create class - type objects

PostPosted: Fri Mar 25, 2016 1:01 pm
by Kilinich
Demo of that combo usage.
Rating: rated 6.1
Filesize: 35.65 kB
Comments: 5
Ratings: 3
download