How to change box A if box B is hit bylaser
5 posts • Page 1 of 1
How to change box A if box B is hit bylaser
Hello. I'm trying to figure out if its possible to change the properties of box A, say change the opacity to 0.0, if box B is hit by a laser. Ultimately, I want to use this to make a kind of optical transistor. Have a small rectangle near the side of a square act as the gate. If the small rectangle is hit by a laser, make the square's opacity change to 0.0 and thus allow the other laser to pass through to activate other transistors. Thanks for your help.
- Gildon
- Posts: 4
- Joined: Thu Aug 15, 2013 10:17 am
Re: How to change box A if box B is hit bylaser
Simple way is to create scene.my. variable in console and use it for opacity of box A.
in console:
scene.my.a1 = 1
in box A:
color = {[0,0,0,scene.my.a1]}
in box B:
onHitByLaser = (e) => {scene.my.a1 = 0}
Only problem is how to switch it back
it could be done in postStep.
in console:
scene.my.a1 = 1
in box A:
color = {[0,0,0,scene.my.a1]}
in box B:
onHitByLaser = (e) => {scene.my.a1 = 0}
Only problem is how to switch it back
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
Re: How to change box A if box B is hit bylaser
Okay, so I let scene.my.a1 = 1. Then I made the color of box A equal {[0,0,0,scene.my.a1]} which returned {[0.0, 0.0, 0.0, 1]} upon entry. I then followed what you said to do with box B and hit it with a laser. I checked with the console and indeed, scene.my.a1 equaled 0 at that point. Box A, however, did not change its color in response the change in the variable. It's opacity stayed 1. It seems algodoo forgets that I set its color to depend on scene.my.a1.
Oh, and to fix the problem of turning the opacity back to 1, could I possibly use like an if statement? Somehow be like if Box A onHitByLaser = 1, then scene.my.a1 = [0.0.0.0], else scene.my.a1 = [0.0.0.1]
Oh, and to fix the problem of turning the opacity back to 1, could I possibly use like an if statement? Somehow be like if Box A onHitByLaser = 1, then scene.my.a1 = [0.0.0.0], else scene.my.a1 = [0.0.0.1]
- Gildon
- Posts: 4
- Joined: Thu Aug 15, 2013 10:17 am
Re: How to change box A if box B is hit bylaser
Gildon wrote:Okay, so I let scene.my.a1 = 1. Then I made the color of box A equal {[0,0,0,scene.my.a1]} which returned {[0.0, 0.0, 0.0, 1]} upon entry.
You entered it wrong if Algodoo returned {[0.0,0.0,0.0, 1]} (my guess is you left out the curly brackets). It should have returned the exact syntax that you entered: {[0,0,0,scene.my.a1]} . OR another way to do it is to enter the script directly into the color array. Simply highlight the current array and paste the modified array {[0,0,0,scene.my.a1]} into it. As long as the variable is showing for the opacity value, then the opacity will change whenever you change the value in the variable. In either case, don't forget to include the curly brackets.
-

Xray - Posts: 501
- Joined: Sun Jun 17, 2012 6:12 am
- Location: USA
Re: How to change box A if box B is hit bylaser
Show your scene, looks like you just have syntax errors.
Dream of Algodoo as game development engine...
-

Kilinich - [Best bug reporter 2010]
- Posts: 2098
- Joined: Mon Aug 31, 2009 8:27 pm
- Location: South Russia
5 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 3 guests



