Lazor cutter/vaporizor w/ custom variables

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

Lazor cutter/vaporizor w/ custom variables

Postby cdh473 » Sat Sep 05, 2009 6:42 pm

I'm making a pulse rifle, it's got 2 functions- 1 is cut, other is vaporize.
i have a custom boolean variable IN the lazor called vaporize.
in my onLaserHit, I have this:
Code: Select all
(e)=>{vaporize == true && cutter == true ? {e.geom.density = NaN}}

Why is this not working?
It won't ever vaporize an object, just cut it :\
even when i have vaporize set to true.
Please excuse my posts. I am extremely stupid.
User avatar
cdh473
 
Posts: 816
Joined: Tue Sep 01, 2009 12:37 am
Location: Yes

Re: Lazor cutter/vaporizor w/ custom variables

Postby Versieon » Sat Sep 05, 2009 6:45 pm

Your if statement isn't set up correctly, it should be {a} ? {b} : {c}
you have a ? {b}
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: Lazor cutter/vaporizor w/ custom variables

Postby cdh473 » Sat Sep 05, 2009 6:49 pm

err...
umm, i want it to be an AND statement, no else.
so all i really need is
Code: Select all
A && B ? {C}
Please excuse my posts. I am extremely stupid.
User avatar
cdh473
 
Posts: 816
Joined: Tue Sep 01, 2009 12:37 am
Location: Yes

Re: Lazor cutter/vaporizor w/ custom variables

Postby Versieon » Sat Sep 05, 2009 6:52 pm

thats what and if staement is, just not with ==
if a and b are true, do c, else do d
so its {a &&b} ? {c} : {d}

its realy exactly the same, but you have to have all the parts, like brakets, otherwise it won't work
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: Lazor cutter/vaporizor w/ custom variables

Postby cdh473 » Sat Sep 05, 2009 11:21 pm

well, i tried it the way you said, and it didn't work.
Code: Select all
(e)=>{{e.laser.cutter == true && e.laser.vaporize == true}(?)({e.geom.density = NaN}) : ({})}
Please excuse my posts. I am extremely stupid.
User avatar
cdh473
 
Posts: 816
Joined: Tue Sep 01, 2009 12:37 am
Location: Yes

Re: Lazor cutter/vaporizor w/ custom variables

Postby Versieon » Sat Sep 05, 2009 11:39 pm

evidently,algodoo cant read boolean variables with onlaserhit, change vaporize to 1 or 0 and you will have to find a way to convert the cutter to a number or substitute something in for it


(e)=>{{e.laser.vaporize == 1 && e.laser.cut == 1} ? {e.geom.density = NaN} : {}}

that works
User avatar
Versieon
 
Posts: 375
Joined: Tue Sep 01, 2009 4:45 pm

Re: Lazor cutter/vaporizor w/ custom variables

Postby cdh473 » Sat Sep 05, 2009 11:52 pm

ahh, i just changed my method.
here it goes(even though it doesn't work yet):
There is a pulse rifle.
At the end, there is a laser.
By default, it burns through(cuts) every object within a VERY large range, slices it cleanly in half.
Press enter to fire.
Set laser's vaporize variable to 1, it completely vaporizes every object it is fired at.
Please excuse my posts. I am extremely stupid.
User avatar
cdh473
 
Posts: 816
Joined: Tue Sep 01, 2009 12:37 am
Location: Yes

Re: Lazor cutter/vaporizor w/ custom variables

Postby gradyfitz » Sun Sep 06, 2009 11:59 am

cdh473 wrote:I'm making a pulse rifle, it's got 2 functions- 1 is cut, other is vaporize.
i have a custom boolean variable IN the lazor called vaporize.
in my onLaserHit, I have this:
Code: Select all
(e)=>{vaporize == true && cutter == true ? {e.geom.density = NaN}}

Why is this not working?
It won't ever vaporize an object, just cut it :\
even when i have vaporize set to true.


As already stated, you need an else statement, regardless of whether you want to have something happen in the event of a false value. To save time with your code, you could just use:

Code: Select all
vaporize && cutter ? {e.geom.density = NaN} : {}


This just eliminates some un-necessary questions, it makes the code smaller too :).
Also, I thought I'd let you work it out yourself (it's not too complicated :D), but, you would not be able to modify the object in normal circumstances, because a cutter generates two new objects, you should modify your code to delete the objects, also, why do you want to have cutter AND vaporize? Wouldn't it make sense to have just one or the other? :D
Mechanisms: 18 Mechanisms.
Thyme: Tutorial - Variables/Commands List.
Thymechanic
gradyfitz
 
Posts: 174
Joined: Tue Sep 01, 2009 8:33 am
Location: Victoria, Australia

Re: Lazor cutter/vaporizor w/ custom variables

Postby RaRaMalum » Sun Sep 06, 2009 12:41 pm

I think you will have some problems getting this to work as a laser thats cutting doesn't register a laser hit and neither does the object beeing cut.

so to get this to work you'll need another laser, but that might get messy as the laser thats turning stuff into water will do that to any object it hits.
Phundamentalists, come to the dark side.
We have much cooler toys.
User avatar
RaRaMalum
[Best newcomer 2010]
 
Posts: 280
Joined: Mon Aug 31, 2009 10:47 pm


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests

cron