WHY IS MY SCRIPTING NOT WORKING?!

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

WHY IS MY SCRIPTING NOT WORKING?!

Postby BAZOOKA » Thu Apr 25, 2013 11:29 am

Hello guys...sulk sulk...
I put this script into the timeToLive bracket
Code: Select all
{scene.my.livetime + 10}

So that I don't have to change the timeToLive number every time I alter. All I have to do is change the scene.my.livetime variable.
HOWEVER, the geometry doesn't disappear after ten seconds! What is going on? Can anyone suggest and tell me how to change the script so it works?! :problem:
Some science teacher said one day,'Remember to leave the water dry...'
User avatar
BAZOOKA
 
Posts: 22
Joined: Fri Oct 26, 2012 5:45 pm

Re: WHY IS MY SCRIPTING NOT WORKING?!

Postby monstertje3 » Thu Apr 25, 2013 5:58 pm

What value do you have for scene.my.livetime?
if it is also 10, the object should dissapear after 20 seconds
Basically, there are only 10 types of people in the world. Those who know binary, and those who don't.
Light travels faster than sound. That's why some people appear bright until they open their mouths.
User avatar
monstertje3
 
Posts: 343
Joined: Sat Sep 05, 2009 4:29 pm
Location: N-H, NL

Re: WHY IS MY SCRIPTING NOT WORKING?!

Postby electronicboy » Thu Apr 25, 2013 8:04 pm

Also, that variable might not work unless the object was spawned with it already set.
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: WHY IS MY SCRIPTING NOT WORKING?!

Postby BAZOOKA » Sat Apr 27, 2013 6:52 am

No, guys...
I am currently working on a spacecraft (Space Shuttle Columbia) for my school project, and i want Columbia to be separated from the SRB (solid rocket boosters) and the oil tank after 45 seconds (as I don't have too much time for my presentation). Therefore, to stop the variable from changing, I added a laser that fires at a box, which says:
Code: Select all
onHitByLaser: (e)=>{scene.my.livetime = 0}

and on the connection bolts (Columbia to SRB+Oiltank):
Code: Select all
timeToLive: {scene.my.livetime + 45}

However, it doesn't work, as I have told you before.
Here's the not-working scene.
Please help me fix it! The deadline for my project is in about a week!!
Attachments
Space Shuttle Columbia + Thruster.phz
Please HELP!!
(75.49 KiB) Downloaded 28 times
Some science teacher said one day,'Remember to leave the water dry...'
User avatar
BAZOOKA
 
Posts: 22
Joined: Fri Oct 26, 2012 5:45 pm

Re: WHY IS MY SCRIPTING NOT WORKING?!

Postby Ivan » Sat Apr 27, 2013 11:27 am

BAZOOKA wrote:...Therefore, to stop the variable from changing, I added a laser that fires at a box, which says:
Code: Select all
onHitByLaser: (e)=>{scene.my.livetime = 0}

That's not necessary as the variable won't be changing unless a scripted so.
If you put it somwhere like:
Code: Select all
Timetolive = {scene.my.livetime}
it's only going to be read from, not written to.
So, both this laser and the laser that sets the frequency to 100 aren't necessary, because the frequency won't change. It will be saved with the scene and there is no need to set the frequency on every laser hit.
If I understood you well, you want the rocket to separate from the SRB 45 seconds after the simulation starts. Than you just have to set TimeToLive to 45 in the script menu (TimeToLive: 45).
User avatar
Ivan
 
Posts: 203
Joined: Tue Oct 06, 2009 2:01 pm
Location: Croatia

Re: WHY IS MY SCRIPTING NOT WORKING?!

Postby BAZOOKA » Tue Apr 30, 2013 3:25 pm

Yes, but the thrusters in the SRB and the fixates also rely on the scene.my.livetime variable...
So what IS going on?
Some science teacher said one day,'Remember to leave the water dry...'
User avatar
BAZOOKA
 
Posts: 22
Joined: Fri Oct 26, 2012 5:45 pm

Re: WHY IS MY SCRIPTING NOT WORKING?!

Postby electronicboy » Tue Apr 30, 2013 4:06 pm

Ivan wrote:If you put it somwhere like:
Code: Select all
Timetolive = {scene.my.livetime}
it's only going to be read from, not written to.

I've done a quick look into this, and the problem comes from the use of {} In the Timetolive variable.
Algodoo writes back to this variable as a countdown, and by using { }, You're actually telling algodoo to be quite, and accept the new variable, which means that algodoo can't count down!

If you want to use the { } in the Timetolive variable, you will have to make scene.my.livetime count down as sim.time passes, AND you will have to make sure that the variable can go negative, otherwise your {scene.my.livetime + 4} will be stuck at +4 as scene.my.livetime gets stuck at 0 ( + 4 = 4 ).
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: WHY IS MY SCRIPTING NOT WORKING?!

Postby BAZOOKA » Wed May 01, 2013 11:11 am

So...How do you do that? I've only learnt a small portion of Thyme, and that includes only spawning stuff, if/or functions, and the weird (for)(40,(i)=...) (AND I'm not even sure if they're right... :oops: ), so how do you fix these problems?
Some science teacher said one day,'Remember to leave the water dry...'
User avatar
BAZOOKA
 
Posts: 22
Joined: Fri Oct 26, 2012 5:45 pm

Re: WHY IS MY SCRIPTING NOT WORKING?!

Postby electronicboy » Wed May 01, 2013 11:31 am

Time to use a laser!
On the OnLaserHit,

scene.my.timetolive = scene.my.livetime - sim.time

When using this code, make sure that scene.my.timetolive is set BEFORE you first press start, otherwise everything will be out of time.
The only downside to this code is that it requires the sim to start when sim.time = 0.

Edit: sorry, off my head, updated code above
Timetolive - place on objects
livetime - time for the object to survive!
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: WHY IS MY SCRIPTING NOT WORKING?!

Postby Xray » Fri May 03, 2013 4:13 am

The problem is you are using a variable in the TimeToLive counter which, instead, should be a constant:
{
scene.my.livetime + 10
}

Because of the fact that TimeToLive is a count-down timer, it requires a fixed numerical value. If you use a variable instead of a number, the variable's value repeatedly gets written to the TimeToLive counter with each scan of the simulation, which has an effect of resetting the count each time around. In other words, the TimeToLive count never is allowed to count down!

Workaround: If you want to use a calculated variable for the TimeToLive count, then use the variable (in this case, scene.my.livetime, to plug the value directly into the TimeToLive counter rather than using the variable itself as the count. If this sounds confusing, just copy this code:

PostStep= (e)=>{
timeToLive = scene.my.livetime;
postStep = (e)=>{}
}

Here, I'm using PostStep in the same geometry as the timeToLive counter. You can set scene.my.livetime to the desired value, and when the simulation starts, the value will get written to the timeToLive counter ONLY ONE TIME. As you can see, the next instruction, postStep = (e)==>{}, deletes all the script in PostStep, which will prevent timeToLive from getting written to again.

There are many ways to skin a cat, and this is just one way to set timeToLive with a calculated value.

Hope this helps!
User avatar
Xray
 
Posts: 501
Joined: Sun Jun 17, 2012 6:12 am
Location: USA

Re: WHY IS MY SCRIPTING NOT WORKING?!

Postby BAZOOKA » Mon May 06, 2013 5:27 pm

OOH! Thanks for the scripting. I will DEFINITELY try that out (as I told you guys, I am basically crappy at scripting... :problem: )
Some science teacher said one day,'Remember to leave the water dry...'
User avatar
BAZOOKA
 
Posts: 22
Joined: Fri Oct 26, 2012 5:45 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 2 guests