Spawning spring with length as variable
18 posts • Page 1 of 1
Spawning spring with length as variable
as title says, i cant seem to do it
it always spawns the spring with a fixed length of 0.1 or whatever i set the BSWireLength to
- 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
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.
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Spawning spring with length as variable
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
What's your entire spawn code?
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Spawning spring with length as variable
- 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
That works, too
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.
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.
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Spawning spring with length as variable
well it SHOULD work but it just doesent, have a look
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
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
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.
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Spawning spring with length as variable
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
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
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
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
Intermediate Phuner
- Cs24
- Posts: 41
- Joined: Tue Nov 03, 2009 5:30 am
Re: Spawning spring with length as variable
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
Ok managed to work it out
updated the scene if anybody interested, yet another part of my bigass project done
updated the scene if anybody interested, yet another part of my bigass project done
- Mr_Stabby
- Posts: 155
- Joined: Wed Dec 16, 2009 12:16 am
Re: Spawning spring with length as variable
good work
What's the difference between ".length" and ";length"? It doesn't seem like there's any
- 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
Intermediate Phuner
- Cs24
- Posts: 41
- Joined: Tue Nov 03, 2009 5:30 am
Re: Spawning spring with length as variable
. 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 but thats the best explanation i can give
(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 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
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?
-
KarateBrot - Posts: 825
- Joined: Mon Aug 31, 2009 7:32 pm
- Location: Germany
Re: Spawning spring with length as variable
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
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
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
18 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 4 guests