Create class - type objects

About advanced scenes, and the Thyme scripting language used in Algodoo.

Create class - type objects

Postby Kilinich » Thu Mar 17, 2016 4:44 pm

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
  }
})
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Create class - type objects

Postby pnvv » Sat Mar 19, 2016 5:45 pm

You're a fokn genius.

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

(/)(°,,,°)(/)
User avatar
pnvv
 
Posts: 670
Joined: Tue Aug 26, 2014 11:46 pm
Location: Disunited States of America

Re: Create class - type objects

Postby Kilinich » Fri Mar 25, 2016 9:11 am

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.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Create class - type objects

Postby Xray » Fri Mar 25, 2016 9:23 am

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:
User avatar
Xray
 
Posts: 500
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: Create class - type objects

Postby Kilinich » Fri Mar 25, 2016 1:01 pm

Demo of that combo usage.
Rating: rated 6.1
Filesize: 35.65 kB
Comments: 5
Ratings: 3
download
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 3 guests

cron