Spawn variable box text Question!

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

Spawn variable box text Question!

Postby guyboy » Sun Feb 07, 2010 2:24 am

I'm trying to spawn a box that comes with an auto-updating box text. (using the {} brackets)
The problem is that when I use the following code:
Code: Select all
Scene.addBox({text := {math.toString(scene.my.num1)}});

The boxes come out with the static value of scene.my.num1 at the time of creation instead of the desired
Code: Select all
{math.toString(scene.my.num1)}

Because Algodoo evaluates {math.toString(scene.my.num1)} before spawning the object.

Is there any way to fix this?
ImageImage
Human horse pasture expansion OpenGL Book Hall
Kwon owned Version (C) 2002-2008
User avatar
guyboy
 
Posts: 80
Joined: Mon Aug 31, 2009 6:19 pm
Location: Ḻ̘̬͕͍͚̥͈͚͖̝̜̲͕̭̩ͅ

Re: Spawn variable box text Question!

Postby Mystery » Sun Feb 07, 2010 9:50 am

Create scene.my.num1 (scene.my.num := whatever)after or at the same time the box is spawned.
User avatar
Mystery
 
Posts: 2802
Joined: Thu Sep 03, 2009 1:16 pm
Location: Southern Australia

Re: Spawn variable box text Question!

Postby Kilinich » Sun Feb 07, 2010 11:57 am

guyboy wrote:I'm trying to spawn a box that comes with an auto-updating box text. (using the {} brackets)
The problem is that when I use the following code:
Code: Select all
Scene.addBox({text := {math.toString(scene.my.num1)}});

The boxes come out with the static value of scene.my.num1 at the time of creation instead of the desired
Code: Select all
{math.toString(scene.my.num1)}

Because Algodoo evaluates {math.toString(scene.my.num1)} before spawning the object.
Is there any way to fix this?


Search "dynamic" in thyme topic :thumbup:
(scene.addbox({})).text = {""+scent.my.text}
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: Spawn variable box text Question!

Postby guyboy » Sun Feb 07, 2010 2:52 pm

That's awesome Kilinich, thanks! :thumbup:
But there still is something wrong :(
This works:
Code: Select all
(e)=>{ (Scene.addBox({})).text = {math.toString(scene.my.num1)} }

But this doesn't:
Code: Select all
(e)=>{ (scene.my.generate1 > 0) ? { (Scene.addBox({})).text = {math.toString(scene.my.num1)}; scene.my.generate1 = scene.my.generate1 - 1 } : {} }

whaa?? :crazy:
Last edited by guyboy on Sun Feb 07, 2010 3:25 pm, edited 1 time in total.
ImageImage
Human horse pasture expansion OpenGL Book Hall
Kwon owned Version (C) 2002-2008
User avatar
guyboy
 
Posts: 80
Joined: Mon Aug 31, 2009 6:19 pm
Location: Ḻ̘̬͕͍͚̥͈͚͖̝̜̲͕̭̩ͅ

Re: Spawn variable box text Question!

Postby Kilinich » Sun Feb 07, 2010 3:14 pm

guyboy wrote:That's awesome Kilinich, thanks! :thumbup:
But there still is something wrong :(

Like what?
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: Spawn variable box text Question!

Postby guyboy » Sun Feb 07, 2010 3:26 pm

Kilinich wrote:
guyboy wrote:That's awesome Kilinich, thanks! :thumbup:
But there still is something wrong :(

Like what?

Like what I edited above.
ImageImage
Human horse pasture expansion OpenGL Book Hall
Kwon owned Version (C) 2002-2008
User avatar
guyboy
 
Posts: 80
Joined: Mon Aug 31, 2009 6:19 pm
Location: Ḻ̘̬͕͍͚̥͈͚͖̝̜̲͕̭̩ͅ

Re: Spawn variable box text Question!

Postby Kilinich » Mon Feb 08, 2010 1:26 pm

guyboy wrote:Like what I edited above.

What errors/warnings you got in console?
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: Spawn variable box text Question!

Postby guyboy » Mon Feb 08, 2010 8:40 pm

Kilinich wrote:
guyboy wrote:Like what I edited above.

What errors/warnings you got in console?

With the first code, nothing, with the second code:
console wrote:
Code: Select all
19:33:42: -- Warning: Exception thrown: Cannot find identifier "math" in "" from /home/linde/work/phun32/Source/script/Expressions.cpp:56: script::ObjectPtr script::Identifier::GetValue(script::ReflectedPtr, const script::Settings&)
19:33:42: -- Warning: Caught exception: Cannot find identifier "math" in "", /home/linde/work/phun32/Source/script/Expressions.cpp:132: virtual script::ObjectPtr script::CodeBlock::Evaluate(script::ReflectedPtr, const script::Settings&)
19:33:42: -- Warning: Failed to evaluate: math.toString(scene.my.num1), Cannot find identifier "math" in ""
19:33:42: -- Warning: Exception thrown: Not a string from /home/linde/work/phun32/Source/script/ValueConversions.cpp:77: T script::ObjectToValue(script::ObjectPtr) [with T = util::String]
19:33:42: -- Warning: Caught Exception: Not a string, /home/linde/work/phun32/Source/script/Attributes.hpp:152: void script::TAttrib<T>::CalcValueFromObject() [with T = std::basic_string<char, std::char_traits<char>, std::allocator<char> >]
19:33:42: -- Warning: text was bound to bad type
ImageImage
Human horse pasture expansion OpenGL Book Hall
Kwon owned Version (C) 2002-2008
User avatar
guyboy
 
Posts: 80
Joined: Mon Aug 31, 2009 6:19 pm
Location: Ḻ̘̬͕͍͚̥͈͚͖̝̜̲͕̭̩ͅ

Re: Spawn variable box text Question!

Postby Kilinich » Mon Feb 08, 2010 8:51 pm

guyboy wrote:That's awesome Kilinich, thanks! :thumbup:
But there still is something wrong :(
This works:
Code: Select all
(e)=>{ (Scene.addBox({})).text = {math.toString(scene.my.num1)} }

But this doesn't:
Code: Select all
(e)=>{ (scene.my.generate1 > 0) ? { (Scene.addBox({})).text = {math.toString(scene.my.num1)}; scene.my.generate1 = scene.my.generate1 - 1 } : {} }

whaa?? :crazy:

I've got it - you need to move code into scene.my. procedure for use it in if-then-else.
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: Spawn variable box text Question!

Postby guyboy » Mon Feb 08, 2010 8:55 pm

Kilinich wrote:
guyboy wrote:That's awesome Kilinich, thanks! :thumbup:
But there still is something wrong :(
This works:
Code: Select all
(e)=>{ (Scene.addBox({})).text = {math.toString(scene.my.num1)} }

But this doesn't:
Code: Select all
(e)=>{ (scene.my.generate1 > 0) ? { (Scene.addBox({})).text = {math.toString(scene.my.num1)}; scene.my.generate1 = scene.my.generate1 - 1 } : {} }

whaa?? :crazy:

I've got it - you need to move code into scene.my. procedure for use it in if-then-else.

Could you please enlighten me on how this is done?
Thank you.
ImageImage
Human horse pasture expansion OpenGL Book Hall
Kwon owned Version (C) 2002-2008
User avatar
guyboy
 
Posts: 80
Joined: Mon Aug 31, 2009 6:19 pm
Location: Ḻ̘̬͕͍͚̥͈͚͖̝̜̲͕̭̩ͅ


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 8 guests

cron