Spawning spring with length as variable

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

Spawning spring with length as variable

Postby Mr_Stabby » Thu Mar 04, 2010 3:49 am

as title says, i cant seem to do it

Code: Select all
scene.my.BSWireLength = 0.1;
(scene.addSpring({             
pos := e.pos;             
geom0 := geomID;             
geom1 := e.other.geomID;             
constant := 100         })).length = {scene.my.BSWireLength}


it always spawns the spring with a fixed length of 0.1 or whatever i set the BSWireLength to
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am

Re: Spawning spring with length as variable

Postby KarateBrot » Thu Mar 04, 2010 3:58 am

It works. The spring got spawned and now I can adjust the length via the variable.
Last edited by KarateBrot on Thu Mar 04, 2010 4:02 am, edited 1 time in total.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Spawning spring with length as variable

Postby Mr_Stabby » Thu Mar 04, 2010 4:02 am

no it doesent work, after the spring is spawned its length = 0.1 not length = {scene.my.BSWireLength}
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am

Re: Spawning spring with length as variable

Postby KarateBrot » Thu Mar 04, 2010 4:03 am

What's your entire spawn code?
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Spawning spring with length as variable

Postby Mr_Stabby » Thu Mar 04, 2010 4:07 am

Code: Select all
(e)=>{
    e.other.textScale == 1.01 ? {         
        e.this.geomID := 1;         
        e.other.geomID := 2;         
        app.step;         
        app.undo;         
        e.other.textScale = 1.02;         
        e.other.collideset = 63;         
        scene.my.BSWireLength = 0.1;         
        (scene.addSpring({             
            pos := e.pos;             
            geom0 := geomID;             
            geom1 := e.other.geomID;             
            constant := 100         
        })).length = {scene.my.BSWireLength}   
    } : {}
}
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am

Re: Spawning spring with length as variable

Postby KarateBrot » Thu Mar 04, 2010 4:20 am

That works, too :D
But maybe you forgot to type in "geomID := whatever" in the bottom line of the scripting menu of both objects before running the simulation the first time.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Spawning spring with length as variable

Postby Mr_Stabby » Thu Mar 04, 2010 4:43 am

well it SHOULD work but it just doesent, have a look
Rating: rated 5
Filesize: 26.79 kB
Comments: 0
Ratings: 1
download


its supposed to be a lifting type thing that goes up and down and grabs onto stuff

W should move up
D should move down
R releases whatever its got
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am

Re: Spawning spring with length as variable

Postby KarateBrot » Thu Mar 04, 2010 5:03 am

The code you posted above works perfectly. That's not the problem. I'm pretty sure in your scene there's an object variable that doesn't get assigned correctly. Maybe it's "check" because it doesn't get the value of e.other.geomID.
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Spawning spring with length as variable

Postby Mr_Stabby » Thu Mar 04, 2010 5:22 am

all the geomIDs are retrieved just as u would do it manually only app.step and app.undo automate the process and all that part of the code works as the springs/fixates to get spawned (if there were no ids they just wouldnt spawn) so i dont think its part of the problem

EDIT: i tried similar scripts and it seems adding a custom variable like this only works on boxes/circles/polys, it seems you just cant spawn a spring with custom var as length
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am

Re: Spawning spring with length as variable

Postby Cs24 » Thu Mar 04, 2010 5:41 am

Works fine except that the spring doesn't spawn with length={BSWireLength}
I think "app.step; app.undo; " is clearing the script from the spring (as with manual undo/redo)

BTW for the spring to lift the circle up it needs to go negative length, but I see you put a script there to prevent that
Newbie Thymer
Intermediate Phuner
Cs24
 
Posts: 41
Joined: Tue Nov 03, 2009 5:30 am

Re: Spawning spring with length as variable

Postby Mr_Stabby » Thu Mar 04, 2010 6:13 am

yea that seems to be the case or rather some pieces of code just dont play together in the same script, did some further testing and for example if i kill the spawner by density=0 or switch off the spawning laser or change the collision before the end of the script it stops working so i guess im gonna have to figure out how to work around all that
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am

Re: Spawning spring with length as variable

Postby Mr_Stabby » Thu Mar 04, 2010 6:57 am

Ok managed to work it out

Rating: rated 5
Filesize: 26.79 kB
Comments: 0
Ratings: 1
download
updated the scene if anybody interested, yet another part of my bigass project done :D
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am

Re: Spawning spring with length as variable

Postby Cs24 » Thu Mar 04, 2010 7:06 am

good work

Code: Select all
(scene.addspring({             geom0 := e.laser.color(0);             geom1 := e.laser.color(1);             pos := e.pos;             constant := 100         })).length = {scene.my.BSWireLength}     } : {}


What's the difference between ".length" and ";length"? It doesn't seem like there's any
Newbie Thymer
Intermediate Phuner
Cs24
 
Posts: 41
Joined: Tue Nov 03, 2009 5:30 am

Re: Spawning spring with length as variable

Postby Mr_Stabby » Thu Mar 04, 2010 8:08 am

. represents pointer of whatever after it comes so for example myobject. = pointer to myobject, in nearly all languages that have pointers you can also define whatever while retrieving the value so
(scene.addbox({})).density=2 really does 3 things
first it accesses a function in a class called "scene" called addbox and creates a box
secondly while it makes it it also extracts the pointer to the created box
and thirdly it uses the pointer to address and modify the subvalue density of that box

so in theory you could do the exact same thing by doing ptr=(scene.addbox({})); eval(ptr+".density=2") with the added benefit of being able to modify the script value any time you choose not just when spawning but i have no clue if that would actually work in thyme

; represents next command so if i were to use that it would instead try to modify the length of the spawner

a bit excessive reply i guess :problem: but thats the best explanation i can give
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am

Re: Spawning spring with length as variable

Postby KarateBrot » Thu Mar 04, 2010 3:24 pm

Mr_Stabby wrote:EDIT: i tried similar scripts and it seems adding a custom variable like this only works on boxes/circles/polys, it seems you just cant spawn a spring with custom var as length

no it works for springs, too. like i said your script you posted above works perfectly. i tested it twice and it worked both times. there really was an error somewhere in your scene which you now bypassed with your new scripting code.
btw. what did you do differently so that it works now?
Image
User avatar
KarateBrot
 
Posts: 825
Joined: Mon Aug 31, 2009 7:32 pm
Location: Germany

Re: Spawning spring with length as variable

Postby Mr_Stabby » Fri Mar 05, 2010 1:14 am

its like whenever the same object that spawned the spring runs another branch of the entire object script or alters the conditions of the initial event that spawned it(time travel!) like change collides or whatever the spring stops working so i moved it to a seperate object dedicated to spawning the spring only
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am

Re: Spawning spring with length as variable

Postby matthijsvz » Fri Jun 11, 2010 4:36 pm

How you can the keys W and S to pull up and down to the keys Y and H
matthijsvz
 
Posts: 1
Joined: Fri Jun 11, 2010 4:34 pm

Re: Spawning spring with length as variable

Postby Mr_Stabby » Fri Jun 11, 2010 7:51 pm

matthijsvz wrote:How you can the keys W and S to pull up and down to the keys Y and H

over 9000
Mr_Stabby
 
Posts: 155
Joined: Wed Dec 16, 2009 12:16 am


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests

cron