[Help] How to do a if else in a onHitByLaser?
4 posts • Page 1 of 1
[Help] How to do a if else in a onHitByLaser?
I'm trying to make a script that will make a variable 1 if a block is being hit by a laser, and 0 if the block is not, this seems very freaking easy, but I cant figure it out,nor can I find anything on how to do it
- vekenti
- Posts: 13
- Joined: Sun Jul 13, 2014 4:43 am
Re: [Help] How to do a if else in a onHitByLaser?
Well, I thought about it, and I realized you might be overthinking it. Then I realized how stupid I was thinking this question was easy.
I think I have a solution now, onHitByLaser = (e)=>{variable = 1; timeToLive = 1}; postStep = (e)=>{timeToLive < 1 ? {variable = 0; timeToLive = 0.5} : {}}
I hope this solution works, I just tested it and it seemed to work.
I think I have a solution now, onHitByLaser = (e)=>{variable = 1; timeToLive = 1}; postStep = (e)=>{timeToLive < 1 ? {variable = 0; timeToLive = 0.5} : {}}
I hope this solution works, I just tested it and it seemed to work.
.
-
icrls984 - Posts: 80
- Joined: Thu Jun 13, 2013 6:33 am
Re: [Help] How to do a if else in a onHitByLaser?
thanks alot!
- vekenti
- Posts: 13
- Joined: Sun Jul 13, 2014 4:43 am
Re: [Help] How to do a if else in a onHitByLaser?
I think to do this you first set a boolean variable whenever the laser hits something, and then activate a very short timer to block the Update method. Whenever the timer runs out(because the laser doesnt hit anything anymore) the Update method sets the variable to false. This would look like the following:
onHitByLaser = (e)=>{
e.this._timer = 0.2;
e.this._hitbylaser = true
}
update = (e)=>{
e.this._timer = e.this._timer - 0.1;
e.this._timer <= 0 ? {
e.this._hitbylaser = false
} : {}}
onHitByLaser = (e)=>{
e.this._timer = 0.2;
e.this._hitbylaser = true
}
update = (e)=>{
e.this._timer = e.this._timer - 0.1;
e.this._timer <= 0 ? {
e.this._hitbylaser = false
} : {}}
- FRA32
- Posts: 229
- Joined: Wed Dec 03, 2014 9:51 pm
4 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 5 guests