Scene.addCircle issues

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

Scene.addCircle issues

Postby lsmft » Sat Feb 19, 2011 9:54 pm

I'm a long time user of phun and algodoo, however I only recently got into scripting. And am experiencing a lot of issues :roll: 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:
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. :crazy:

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. :crazy:

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. :mrgreen:
User avatar
lsmft
 
Posts: 5
Joined: Sat Feb 19, 2011 9:43 pm
Location: Rio

Re: Scene.addCircle issues

Postby Kilinich » Sat Feb 19, 2011 10:20 pm

color, not collor :thumbup:
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Scene.addCircle issues

Postby Kilinich » Sat Feb 19, 2011 10:21 pm

and you must add tracer inside first {} of if condition right after circle spawn.
Dream of Algodoo as game development engine...
User avatar
Kilinich
[Best bug reporter 2010]
 
Posts: 2098
Joined: Mon Aug 31, 2009 8:27 pm
Location: South Russia

Re: Scene.addCircle issues

Postby TC42 » Sat Feb 19, 2011 10:41 pm

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...
Image
Spambot wrote:Nowadays, memes usually are studied less in the field of biology, but more with the arena of psychology along with sociology. But, the major area of a meme, getting embraced and imitated all the time is what’s at any core connected with any meme.
User avatar
TC42
 
Posts: 984
Joined: Sun Jan 09, 2011 1:53 pm
Location: $ sudo apt get-install sandwich_

Re: Scene.addCircle issues

Postby lsmft » Sun Feb 20, 2011 10:47 pm

Kilinich wrote:color, not collor :thumbup:


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.
User avatar
lsmft
 
Posts: 5
Joined: Sat Feb 19, 2011 9:43 pm
Location: Rio

Re: Scene.addCircle issues

Postby TC42 » Sun Feb 20, 2011 10:49 pm

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
Image
Spambot wrote:Nowadays, memes usually are studied less in the field of biology, but more with the arena of psychology along with sociology. But, the major area of a meme, getting embraced and imitated all the time is what’s at any core connected with any meme.
User avatar
TC42
 
Posts: 984
Joined: Sun Jan 09, 2011 1:53 pm
Location: $ sudo apt get-install sandwich_

Re: Scene.addCircle issues

Postby lsmft » Sun Feb 20, 2011 11:18 pm

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
User avatar
lsmft
 
Posts: 5
Joined: Sat Feb 19, 2011 9:43 pm
Location: Rio

Re: Scene.addCircle issues

Postby daniels220 » Sun Feb 20, 2011 11:48 pm

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

Postby lsmft » Mon Feb 21, 2011 12:46 am

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:

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 :)

Rating: rated 5
Filesize: 14.83 kB
Comments: 0
Ratings: 1
download
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.
User avatar
lsmft
 
Posts: 5
Joined: Sat Feb 19, 2011 9:43 pm
Location: Rio

Re: Scene.addCircle issues

Postby daniels220 » Mon Feb 21, 2011 1:31 am

You can simplify
Code: Select all
vel := [e.normal(0) * 20, e.normal(1) * 20];
to
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

Postby TC42 » Mon Feb 21, 2011 6:38 am

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:
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
                })
            }
        })
    } : {}
Image
Spambot wrote:Nowadays, memes usually are studied less in the field of biology, but more with the arena of psychology along with sociology. But, the major area of a meme, getting embraced and imitated all the time is what’s at any core connected with any meme.
User avatar
TC42
 
Posts: 984
Joined: Sun Jan 09, 2011 1:53 pm
Location: $ sudo apt get-install sandwich_

Re: Scene.addCircle issues

Postby lsmft » Mon Feb 21, 2011 9:42 pm

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:
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.
User avatar
lsmft
 
Posts: 5
Joined: Sat Feb 19, 2011 9:43 pm
Location: Rio


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 1 guest