Scene.addCircle issues
12 posts • Page 1 of 1
Scene.addCircle issues
I'm a long time user of phun and algodoo, however I only recently got into scripting. And am experiencing a lot of issues
I'm self taught, and computer science isn't really my forte so I was wondering if anyone could give me a hand. I'm attempting to make a very simple gun that shoots black circles with a red or yellow tracer.
I'm currently attempting to use this script:
it is my understanding that the color code [0.0, 0.0, 0.0, 1.0] should produce the color black. However, all the circles produced are random colors.
Furthermore, the code
Works and shoots out circles, albeit randomly colored circles.
However, when I add in the code
To the end to try and produce the tracer effect, it causes the entire script to stop working, although, it does not show any syntax errors.
If someone could be so kind as to explain where I'm going wrong I'd be very thankful. As I said, I'm a total noob at scripting in all languages, so if you can explain it to me like I'm 4 that would be even more helpful.
I'm currently attempting to use this script:
- Code: Select all
(e)=>{
e.geom.controlleracc = e.geom.controlleracc + 1;
e.geom.controlleracc >= 10 ? {
Scene.addCircle({
radius := 0.06;
collideset := 2;
collor := [0.0, 0.0, 0.0, 1.0];
vel := [e.normal(0) * 30, e.normal(1) * 30];
pos := e.pos
});
e.geom.controlleracc = 0
} : {}(Scene.addPen)({
color := [0.0, 0.0, 0.0, 1.0];
fadeTime := 0.01;
size := 0.03
})
}
it is my understanding that the color code [0.0, 0.0, 0.0, 1.0] should produce the color black. However, all the circles produced are random colors.
Furthermore, the code
- Code: Select all
(e)=>{
e.geom.controlleracc = e.geom.controlleracc + 1;
e.geom.controlleracc >= 10 ? {
Scene.addCircle({
radius := 0.06;
collideset := 2;
collor := [0.0, 0.0, 0.0, 1.0];
vel := [e.normal(0) * 30, e.normal(1) * 30];
pos := e.pos
});
e.geom.controlleracc = 0
} : {}
})
}
Works and shoots out circles, albeit randomly colored circles.
However, when I add in the code
- Code: Select all
(Scene.addPen)({
color := [0.0, 0.0, 0.0, 1.0];
fadeTime := 0.01;
size := 0.03
To the end to try and produce the tracer effect, it causes the entire script to stop working, although, it does not show any syntax errors.
If someone could be so kind as to explain where I'm going wrong I'd be very thankful. As I said, I'm a total noob at scripting in all languages, so if you can explain it to me like I'm 4 that would be even more helpful.
-

lsmft - Posts: 5
- Joined: Sat Feb 19, 2011 9:43 pm
- Location: Rio
Re: Scene.addCircle issues
and you must add tracer inside first {} of if condition right after circle spawn.
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: Scene.addCircle issues
And it should be
You will also have to create a group so that the tracers stay attached to the circles, not the spawner (don't ask), but I'm on one computer, and algodoo is on my other computer, and I don't have that code memorized, so I'll post it in a minute...
- Code: Select all
scene.addpen({color:=[0,0,0,1]; fadetime:=0.01; size:=0.03 pos:=e.pos});
You will also have to create a group so that the tracers stay attached to the circles, not the spawner (don't ask), but I'm on one computer, and algodoo is on my other computer, and I don't have that code memorized, so I'll post it in a minute...
-

TC42 - Posts: 984
- Joined: Sun Jan 09, 2011 1:53 pm
- Location: $ sudo apt get-install sandwich_
Re: Scene.addCircle issues
Kilinich wrote:color, not collor
Ah, but what I fresh pair of eyes can accomplish. I must have read that line of code one-hundred times without catching my typing error.
TC42 wrote:And it should be
- Code: Select all
scene.addpen({color:=[0,0,0,1]; fadetime:=0.01; size:=0.03 pos:=e.pos});
You will also have to create a group so that the tracers stay attached to the circles, not the spawner (don't ask), but I'm on one computer, and algodoo is on my other computer, and I don't have that code memorized, so I'll post it in a minute...
I'm pretty sure I understand, but if you could post that grouping code I'd be very thankful.
EDIT:
Actually, it would seem the grouping is unnecessary.
Using:
- Code: Select all
(e)=>{
e.geom.controlleracc = e.geom.controlleracc + 1;
e.geom.controlleracc >= 3 ? {
Scene.addCircle({
radius := 0.06;
collideset := 2;
color := [0.0, 0.0, 0.0, 1.0];
vel := [e.normal(0) * 30, e.normal(1) * 30];
pos := e.pos
});
Scene.addPen({
color := [0.0, 0.0, 0.0, 1.0];
fadetime := 0.01;
size := 0.03;
pos := e.pos
});
e.geom.controlleracc = 0
} : {}
}
it is fully functional. Shooting black circles with black tracers. I'm assuming because of the placement of the pen code after, as Kilinich said, the first instance of {} on parallel of the addCircle, rendering grouping unnecessary.
Thanks again.
Last edited by lsmft on Sun Feb 20, 2011 11:22 pm, edited 2 times in total.
-

lsmft - Posts: 5
- Joined: Sat Feb 19, 2011 9:43 pm
- Location: Rio
Re: Scene.addCircle issues
For spawning a circle with a tracer, use this code, and modify it as you need to. Honestly, I don't understand it either...
- Code: Select all
scene.addCircle({
pos := e.pos;
collideset := 64
});
scene.addGroup({
name := "selected";
entityIDs := []
});
scene.addPen({
pos := e.pos;
size := 1
-

TC42 - Posts: 984
- Joined: Sun Jan 09, 2011 1:53 pm
- Location: $ sudo apt get-install sandwich_
Re: Scene.addCircle issues
TC42 wrote:For spawning a circle with a tracer, use this code, and modify it as you need to. Honestly, I don't understand it either...
see my above post's edit
-

lsmft - Posts: 5
- Joined: Sat Feb 19, 2011 9:43 pm
- Location: Rio
Re: Scene.addCircle issues
Regarding grouping: what TC42's code is doing is deselecting anything the user may have selected before spawning the tracer, because if there is something selected tracers will attach themselves to it instead of the circle. A more elegant solution would be to assign a geomID to the circle and force the tracer to bind to that, but I'm not sure how. Or you could save the selection somehow, temporarily blank it, and restore it—but I'm betting Thyme can't read the current selection.
- daniels220
- Posts: 95
- Joined: Mon Aug 31, 2009 11:30 pm
Re: Scene.addCircle issues
That's getting way above my skill level. Like I said, I'm a total noob when it comes to scripting. From the tutorial I read I sorta have a grasp on grouping, but not really. They're created using the console, right?
Also: Finalized code:
Black circles, with red tracer
and here is the finalized phunlet, working perfectly.
Also: Finalized code:
- Code: Select all
(e)=>{
e.geom.controlleracc = e.geom.controlleracc + 1;
e.geom.controlleracc >= 17 ? {
Scene.addCircle({
radius := 0.06;
collideset := 2;
color := [0.0, 0.0, 0.0, 1.0];
vel := [e.normal(0) * 20, e.normal(1) * 20];
pos := e.pos
});
Scene.addPen({
color := [1.0, 0.0, 0.08333331, 1.0];
fadetime := 0.05;
size := 0.075;
pos := e.pos
});
e.geom.controlleracc = 0
} : {}
}
Black circles, with red tracer
and here is the finalized phunlet, working perfectly.
Last edited by lsmft on Mon Feb 21, 2011 9:44 pm, edited 1 time in total.
-

lsmft - Posts: 5
- Joined: Sat Feb 19, 2011 9:43 pm
- Location: Rio
Re: Scene.addCircle issues
You can simplify
Other than that, it looks like it should work, and it'll work most of the time without any grouping messiness, so I'd say just use it as is.
- Code: Select all
vel := [e.normal(0) * 20, e.normal(1) * 20];
- Code: Select all
vel := e.normal * 20;
Other than that, it looks like it should work, and it'll work most of the time without any grouping messiness, so I'd say just use it as is.
- daniels220
- Posts: 95
- Joined: Mon Aug 31, 2009 11:30 pm
Re: Scene.addCircle issues
Similarly related to this, I am having trouble with this scene of mine:
[scene]51976[/scene]
It should spawn a tracer on the circle when the circle collides with something, but it is very inconsistant (see scene description for detail). Here's the code I'm using right now:
[scene]51976[/scene]
It should spawn a tracer on the circle when the circle collides with something, but it is very inconsistant (see scene description for detail). Here's the code I'm using right now:
- Code: Select all
{e.geom.controlleracc == 300} ? {
e.geom.controlleracc = 0;
scene.addCircle({
pos := e.pos;
vel := e.normal * 10;
collideset := 1;
color := [0, 0, 0, 1];
radius := 0.05;
restitution := 1;
heterocollide := true;
oncollide := (e)=>{
e.this.heterocollide = false;
scene.addGroup({
name := "selected";
entityIDs := []
});
scene.addpen({
pos := e.pos;
size := 0.1;
color := [0, 0, 0, 1];
fadetime := 1
})
}
})
} : {}
-

TC42 - Posts: 984
- Joined: Sun Jan 09, 2011 1:53 pm
- Location: $ sudo apt get-install sandwich_
Re: Scene.addCircle issues
way above my skill level. I was able to somewhat increase reliability by lowering the size of the tracer and lowering the velocity, which I'm sure you've tired.
But as you said it still randomly attaches to the object it strikes or not at all.
Again though, your idea of grouping seems to be largely unnecessary using the code:
yields pretty much identical results as far as reliability goes. Maybe that can give you some insight as to how to fix the issue? I'm sorry I can't be more of a help.
But as you said it still randomly attaches to the object it strikes or not at all.
Again though, your idea of grouping seems to be largely unnecessary using the code:
- Code: Select all
(e)=>{
{e.geom.controlleracc == 15} ? {
e.geom.controlleracc = 0;
scene.addCircle({
pos := e.pos;
vel := e.normal * 10;
collideset := 2;
color := [0, 0, 0, 1];
radius := 0.05;
restitution := 0.5;
oncollide := (e)=>{
scene.addpen({
pos := e.pos;
vel := e.normal * 2;
size := 0.06;
color := [0, 0, 0, 1];
fadetime := 1
})
}
})
} : {}
}
yields pretty much identical results as far as reliability goes. Maybe that can give you some insight as to how to fix the issue? I'm sorry I can't be more of a help.
-

lsmft - Posts: 5
- Joined: Sat Feb 19, 2011 9:43 pm
- Location: Rio
12 posts • Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest





