onSpawn?

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

onSpawn?

Postby Sonic » Fri May 24, 2013 12:25 am

I was wondering if anyone could tell me how the onSpawn command works. I'm trying to make a box that when it spawns another box that one spawns another box and then that one spawns another box, repeat ad ininitum until the whole thing is filled and the scene crashes. Is that possible, and if so how? I haven't used Thyme in over two years so I'm a bit rusty.
I do stuff and break things. You know how it is.
Image
User avatar
Sonic
 
Posts: 1467
Joined: Tue Sep 01, 2009 6:18 pm
Location: America!!!

Re: onSpawn?

Postby electronicboy » Fri May 24, 2013 6:20 pm

onSpawn should do that, I've not looked into it myself, but the onspawn code obviously has to be set by a code spawning the object for it to run "onspawn".

If that makes sense in my sleep deprived state :P
When asking for help, READ THE STICKIES!
electronicboy
 
Posts: 1694
Joined: Mon Aug 31, 2009 6:18 pm

Re: onSpawn?

Postby Sonic » Sun May 26, 2013 7:02 am

So it would be possible to make a grey goo style end of the world box?
Last edited by Sonic on Mon May 27, 2013 5:40 pm, edited 1 time in total.
I do stuff and break things. You know how it is.
Image
User avatar
Sonic
 
Posts: 1467
Joined: Tue Sep 01, 2009 6:18 pm
Location: America!!!

Re: onSpawn?

Postby Someone Else » Mon May 27, 2013 5:12 am

Try something like this:
Code: Select all
onSpawn = (e)>={
  scene.addBox({
    pos := pos
    size := [1, 1]
    onSpawn := onSpawn
  })
}

However, (I'm guessing, not tested- this might crash immediately) this will spawn one box per frame (100 per second, at default sim.frequency), which will take a while to crash Algodoo.
So instead, this code:
Code: Select all
onCollide = (e)>={
  scene.addBox({
    pos := e.pos
    size := [1, 1]
    onCollide := onCollide
  })
}

Might work just a little bit better. It also solves the problem of having to spawn the box to run the code to spawn the next one- each frame, each box will collide with quite a few of the others, so the number of boxes increases very, very fast. I'm not sure on the exact nature of the shape of a plot of the number of boxes versus time (Not sure if it's exponential or something steeper), but the result will be a crashed Algodoo very soon after the original box touches something.

As for "great goo"- I'm not acquainted with that, but (making a random guess as to what you're going after) I'd recommend something to do with either counters in postStep scripts or finite timeToLive and onDeath scripts - you might be able to adapt the code I used in this scene for your purposes:
Rating: rated 5
Filesize: 11 kB
Comments: 1
Ratings: 1
download
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: onSpawn?

Postby jon_joy_1999 » Mon May 27, 2013 7:29 am

gray goo (not great goo, as the OP said) is a hypothetical end-of-the-world scenario involving nanotechnology in which out of control self-replicating nanobots consume all matter on earth while replicating themselves. the term "grey goo" doesn't indicate color or texture, but instead that the nanobots capable of this might be less inspiring than crabgrass
Image
BSrac = BoincStats recent average credit
I'd rather be network computing.
jon_joy_1999
 
Posts: 233
Joined: Fri Dec 09, 2011 12:51 am

Re: onSpawn?

Postby Someone Else » Tue May 28, 2013 5:13 am

jon_joy_1999 wrote:gray goo (not great goo, as the OP said) is a hypothetical end-of-the-world scenario involving nanotechnology in which out of control self-replicating nanobots consume all matter on earth while replicating themselves. the term "grey goo" doesn't indicate color or texture, but instead that the nanobots capable of this might be less inspiring than crabgrass

Sounds a bit like the recursive explosives I made a while back (inspired by gmowebster's recursive bomb)...
Rating: rated 7.2
Filesize: 143.74 kB
Comments: 9
Ratings: 7
download
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy

Re: onSpawn?

Postby Sonic » Wed May 29, 2013 5:49 am

Someone Else wrote:Try something like this:
Code: Select all
onSpawn = (e)>={
  scene.addBox({
    pos := pos
    size := [1, 1]
    onSpawn := onSpawn
  })
}

However, (I'm guessing, not tested- this might crash immediately) this will spawn one box per frame (100 per second, at default sim.frequency), which will take a while to crash Algodoo.
So instead, this code:
Code: Select all
onCollide = (e)>={
  scene.addBox({
    pos := e.pos
    size := [1, 1]
    onCollide := onCollide
  })
}

Might work just a little bit better. It also solves the problem of having to spawn the box to run the code to spawn the next one- each frame, each box will collide with quite a few of the others, so the number of boxes increases very, very fast. I'm not sure on the exact nature of the shape of a plot of the number of boxes versus time (Not sure if it's exponential or something steeper), but the result will be a crashed Algodoo very soon after the original box touches something.

As for "great goo"- I'm not acquainted with that, but (making a random guess as to what you're going after) I'd recommend something to do with either counters in postStep scripts or finite timeToLive and onDeath scripts - you might be able to adapt the code I used in this scene for your purposes:
Rating: rated 5
Filesize: 11 kB
Comments: 1
Ratings: 1
download


I can't seem to get your code to work. It keeps telling me it can't compile it.
I do stuff and break things. You know how it is.
Image
User avatar
Sonic
 
Posts: 1467
Joined: Tue Sep 01, 2009 6:18 pm
Location: America!!!

Re: onSpawn?

Postby Someone Else » Sun Jun 02, 2013 8:46 am

Sonic wrote:
Someone Else wrote:Try something like this:
Code: Select all
onSpawn = (e)>={
  scene.addBox({
    pos := pos
    size := [1, 1]
    onSpawn := onSpawn
  })
}

However, (I'm guessing, not tested- this might crash immediately) this will spawn one box per frame (100 per second, at default sim.frequency), which will take a while to crash Algodoo.
So instead, this code:
Code: Select all
onCollide = (e)>={
  scene.addBox({
    pos := e.pos
    size := [1, 1]
    onCollide := onCollide
  })
}

Might work just a little bit better. It also solves the problem of having to spawn the box to run the code to spawn the next one- each frame, each box will collide with quite a few of the others, so the number of boxes increases very, very fast. I'm not sure on the exact nature of the shape of a plot of the number of boxes versus time (Not sure if it's exponential or something steeper), but the result will be a crashed Algodoo very soon after the original box touches something.

As for "great goo"- I'm not acquainted with that, but (making a random guess as to what you're going after) I'd recommend something to do with either counters in postStep scripts or finite timeToLive and onDeath scripts - you might be able to adapt the code I used in this scene for your purposes:
Rating: rated 5
Filesize: 11 kB
Comments: 1
Ratings: 1
download


I can't seem to get your code to work. It keeps telling me it can't compile it.


That may be, I haven't tested it- although, which code are you referring to, exactly, and where did you put it?
Both of the above scripts are intended to go into a geom (not the console)- when I say
Code: Select all
onCollide = (e)=>{ <insert code here> }

I mean that the onCollide variable should be set equal to "(e)=>{ <insert code here> }" by replacing the "(e)=>{}" that was already in onCollide with "(e)=>{ <insert code here> }"; or drop "<insert code here>" between the curly braces in "(e)=>{}".

Oh, wait, I see what I did. I forgot the semicolons, and made a few other syntax errors. Time to test these scripts!

Code: Select all
onSpawn = (e)=>{
  scene.addBox({
    pos := pos;
    size := [1, 1];
    onSpawn := onSpawn
  })
}

This code seems to spawn the next box in the same frame as the previous one- proving that onSpawn scripts act instantaneously, and causing my Algodoo to hang. It didn't crash (I force-quit before it did- but I waited a while before I did that), but I ran it in Linux through Wine, so I don't know what would happen on another computer.
I didn't actually see any of the spawned circles- I triggered the script, and Algodoo was never heard from again. The screen did not update, aside from when Ubuntu darkened the screen to indicate that the program wasn't responding.

Code: Select all
onCollide = (e)=>{
  scene.addBox({
    pos := e.pos;
    size := [1, 1];
    onCollide := onCollide
  })
}

A dozen boxes appeared (that I could see- probably more hidden behind them), then Algodoo hung for about fifteen seconds, then crash. An actual, program-closes-itself crash, not the infinite loop of the previous script. (Exponential Growth for the Win!)

I've also put together a scene based off the scene in my previous post, in an attempt at creating world-eating goo.
Rating: rated 5
Filesize: 15.59 kB
Comments: 0
Ratings: 1
download
Matthias Wandel is epic, in my humble opinion.
I love my brain...
TC42 wrote:Also, your sig is too big, please change it.

ARE YA HAPPY NOW?????

Thymechanic/Phundamentalist

Recently, I discovered something a lot of you probably already knew: Minecraft is awesome.
Due to this, I may not be as active as usual for a while.
User avatar
Someone Else
 
Posts: 1147
Joined: Sun Nov 21, 2010 10:53 pm
Location: The Milky Way Galaxy


Return to Thyme scripting

Who is online

Users browsing this forum: No registered users and 12 guests