Page 1 of 1

Lazor cutter/vaporizor w/ custom variables

PostPosted: Sat Sep 05, 2009 6:42 pm
by cdh473
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.

Re: Lazor cutter/vaporizor w/ custom variables

PostPosted: Sat Sep 05, 2009 6:45 pm
by Versieon
Your if statement isn't set up correctly, it should be {a} ? {b} : {c}
you have a ? {b}

Re: Lazor cutter/vaporizor w/ custom variables

PostPosted: Sat Sep 05, 2009 6:49 pm
by cdh473
err...
umm, i want it to be an AND statement, no else.
so all i really need is
Code: Select all
A && B ? {C}

Re: Lazor cutter/vaporizor w/ custom variables

PostPosted: Sat Sep 05, 2009 6:52 pm
by Versieon
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

Re: Lazor cutter/vaporizor w/ custom variables

PostPosted: Sat Sep 05, 2009 11:21 pm
by cdh473
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}) : ({})}

Re: Lazor cutter/vaporizor w/ custom variables

PostPosted: Sat Sep 05, 2009 11:39 pm
by Versieon
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

Re: Lazor cutter/vaporizor w/ custom variables

PostPosted: Sat Sep 05, 2009 11:52 pm
by cdh473
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.

Re: Lazor cutter/vaporizor w/ custom variables

PostPosted: Sun Sep 06, 2009 11:59 am
by gradyfitz
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

Re: Lazor cutter/vaporizor w/ custom variables

PostPosted: Sun Sep 06, 2009 12:41 pm
by RaRaMalum
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.