Bug or bad script.

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

Bug or bad script.

Postby Mystery » Fri Mar 05, 2010 6:11 am

Been experimenting lately with something i call "Object Lifespan"
Code: Select all
density := {2 - ({sim.time >= controlleracc} ? {2} : {0})}

if controlleracc is
Code: Select all
sim.time + 1
Then in 1 second its density will become 0 thus deleting it's self.

There are two problems with this
1. only works with a single object at one time (any more and it deletes the script from the object spawned first)
2. leaves an error report in the console.
Code: Select all
14:36:11: -- Warning: Exception thrown: Cannot find identifier "math" in "" from C:\emilk\phun\trunk\Source\script\Expressions.cpp:56: class util::SharedPtr<class script::Object> __thiscall script::Identifier::GetValue(class util::SharedPtr<class script::Reflected>,const class script::Settings &)
14:36:11: -- Warning: Caught exception: Cannot find identifier "math" in "", C:\emilk\phun\trunk\Source\script\Expressions.cpp:132: class util::SharedPtr<class script::Object> __thiscall script::CodeBlock::Evaluate(class util::SharedPtr<class script::Reflected>,const class script::Settings &)
14:36:11: -- Warning: Failed to evaluate: 2 - ({sim.time >= controlleracc} ? {2} : {0}), Cannot find identifier "math" in ""
14:36:11: -- Warning: Exception thrown: Not a real from C:\emilk\phun\trunk\Source\script\ValueConversions.cpp:32: long double __cdecl script::ObjectToValue<long double>(class util::SharedPtr<class script::Object>)
14:36:11: -- Warning: Caught Exception: Not a real, c:\emilk\phun\trunk\source\script\Attributes.hpp:152: void __thiscall script::TAttrib<float>::CalcValueFromObject(void)
14:36:11: -- Warning: density was bound to bad type


Any ideas what's wrong honestly i'm stumped.
User avatar
Mystery
 
Posts: 2802
Joined: Thu Sep 03, 2009 1:16 pm
Location: Southern Australia

Re: Bug or bad script.

Postby KarateBrot » Fri Mar 05, 2010 3:21 pm

Very helpful link
Another interesting link

You have to do it this way:
(scene.add*()).density = { }

For example when spawning a circle (can be done with everything else, too):
Code: Select all
( scene.addcircle({ pos := [0, 0]; radius := 0.5}) ).density = { sim.time >= controlleracc ? {0} : {2} }


And btw. you can't mix integer or float values with boolean values. That's why the "math" error in the console appears. So only make the math in if statements in the THEN or ELSE part. But for your example you don't need to substract anything.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Bug or bad script.

Postby Versieon » Sat Mar 06, 2010 12:05 am

The other thing is that the controllerAcc value will not be from the spwned object, but from the spawner itself. i made something like this but it didn't work because of that, as you can see in the links.
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 5 guests