What's wrong with my script?

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

What's wrong with my script?

Postby Rideg » Fri Aug 20, 2010 2:53 am

Hello. I'm trying to make a random xPos spawner. It should spawn circles at different positions within a range between [1.0, y] and [5.0, y]. I can't find what's wrong. Maybe I'm just tired and it's obvious. But anyway I'd really appriciate if I got this solved.

Thank you.

Code: Select all
(e)=>{
    sim.time - e.geom.controllerAcc >= 0.3 ? {
        Artillery = scene.addCircle({radius := 0.5});
        randomPos = (Artillery.color(0) * ((5) - (1)) + (1));
        Artillery.pos = [randomPos, 1.0];
        e.geom.controllerAcc = sim.time
    } : {}
}
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden

Re: What's wrong with my script?

Postby Kilinich » Fri Aug 20, 2010 7:44 am

You can't change pos of already spawned geom.

Use something like that (I didn't test it but you got the idea).
Code: Select all
    (e)=>{
        sim.time - e.geom.controllerAcc >= 0.3 ? {
            randomPos := 1 + ((sim.time * 7) % 1) * 4;
            scene.addCircle({
               radius := 0.5;
               pos = [randomPos, 1.0]
            });
            e.geom.controllerAcc = sim.time
        } : {}
    }
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: What's wrong with my script?

Postby Rideg » Fri Aug 20, 2010 4:11 pm

looks good. I'll try it when I get back home. I'm going out of town now.

Does it spawn a ball at a random position between 1 and 5?
Image
make sure to check out my work.
User avatar
Rideg
 
Posts: 948
Joined: Tue Dec 15, 2009 5:17 pm
Location: Östersund, Sweden


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 4 guests