user objects with fields and methods
8 posts • Page 1 of 1
user objects with fields and methods
hello!
is there a way to create your own objects, for example,
and then access its fields and methods like
there are global objects organized like that, math.* for example.
I tried the above definition, but then if I try to access scene.my.object.a,
it throws an error:
as far as I understand, a ClassObject can have children, but how do I declare my own ClassObject?
is there a way to create your own objects, for example,
- Code: Select all
scene.my.object = {a=0; b="foo"; twice=(x)=>{x*2}}
and then access its fields and methods like
- Code: Select all
scene.my.object.a, scene.my.object.twice(100)
there are global objects organized like that, math.* for example.
I tried the above definition, but then if I try to access scene.my.object.a,
it throws an error:
- Code: Select all
Failed to evaluate: scene.my.object.a, Object scene.my.object cannot have children; it is not a class object
as far as I understand, a ClassObject can have children, but how do I declare my own ClassObject?
- ukuru.gejacoya
- Posts: 10
- Joined: Sun Jun 23, 2013 2:55 pm
Re: user objects with fields and methods
There is no way to create such object, but you could use some geom for that.
Foe example make invisible box with onSpawn = (e) => {scene.my.object1 = e.this} and use it in scripts as object, just don't forget to add _ symbol to variables names for saving with scene.
Foe example make invisible box with onSpawn = (e) => {scene.my.object1 = e.this} and use it in scripts as object, just don't forget to add _ symbol to variables names for saving with scene.
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: user objects with fields and methods
got it! spasibo! 
update: it's possible to use entity instead of e.this:
update: it's possible to use entity instead of e.this:
- Code: Select all
onSpawn = (e) => {scene.my.object1 = entity}
- ukuru.gejacoya
- Posts: 10
- Joined: Sun Jun 23, 2013 2:55 pm
Re: user objects with fields and methods
but then all my _local variables get stuck in the global scope after onSpawn executes, if I close the scene they are still available through console. I really can't grok thyme... 
step by step example:
1. file > new scene
2. check for _foo variable in global scope: _foo -> undefined
3. create a box
4. right click it > script menu > _foo="bar" //the _foo is added
5. recheck the global scope: console > _foo -> undefined
6. enter onSpawn into the box property window: (e)=>{scene.my.box = entity} //or (e)=>{scene.my.box = e.this}, no diff
7. save the scene
8. reload the saved one
9. console > _foo -> undefined //OK
10. overwrite the scene
11. reload the scene
12. console > _foo -> bar //
what's just happened? it crawls into global scope upon overwriting the scene
13. new scene
14. console > _foo -> bar //
still there.
this is beyond me.
step by step example:
1. file > new scene
2. check for _foo variable in global scope: _foo -> undefined
3. create a box
4. right click it > script menu > _foo="bar" //the _foo is added
5. recheck the global scope: console > _foo -> undefined
6. enter onSpawn into the box property window: (e)=>{scene.my.box = entity} //or (e)=>{scene.my.box = e.this}, no diff
7. save the scene
8. reload the saved one
9. console > _foo -> undefined //OK
10. overwrite the scene
11. reload the scene
12. console > _foo -> bar //
13. new scene
14. console > _foo -> bar //
this is beyond me.
- ukuru.gejacoya
- Posts: 10
- Joined: Sun Jun 23, 2013 2:55 pm
Re: user objects with fields and methods
It's even worse than what you had described. After going through those steps that you outlined, I shut down Algodoo and then reopened it, and created a new blank scene. I then checked the console for _foo and it still contained "bar"! I then loaded one of my older saved scenes, and checked the global scope again. _foo was still defined and contained "bar"!
It seems that no matter what I do, _foo is always defined and contains "bar"! I would say that this bug is definitely FUBAR! 
-

Xray - Posts: 501
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: user objects with fields and methods
Well then - forget it) 
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: user objects with fields and methods
thanks for participation, guys!
Xray, it is indeed ... Up Beyond All Recognition
now you have to edit the config.cfg to get rid of it!
Kilinich, ok, trying to forget - but it seemed like a really nice way to incorporate semi-oop techniques into Algodoo
Xray, it is indeed ... Up Beyond All Recognition
Kilinich, ok, trying to forget - but it seemed like a really nice way to incorporate semi-oop techniques into Algodoo
- ukuru.gejacoya
- Posts: 10
- Joined: Sun Jun 23, 2013 2:55 pm
Re: user objects with fields and methods
I have tried:
Scene.my.example -> {v=1;z=45;c=564};
Scene.my.v= scene.my.example.v
It gives me an error too
I think readable could work but I haven't tried yet.
Scene.my.example -> {v=1;z=45;c=564};
Scene.my.v= scene.my.example.v
It gives me an error too
I think readable could work but I haven't tried yet.
- lololoer16_17
- Posts: 18
- Joined: Tue Jan 21, 2014 8:55 pm
- Location: Spain (South)
8 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 4 guests



