Page 1 of 1

Infection

Posted: Sep 29th, '15, 09:41
by bromagosa
Joan Güell, a coworker of mine here at the Citilab -who is a biologist-, has built a simple bacterial infection simulation in GP.

It's an example I love, we used to teach it in Scratch all the time because it can be improved a lot, and kids love adding features and "genetically modifying" bacteria!

* You can easily add resistance to bacteria by just counting how many times a particular bacteria has been infected and using that when deciding whether it should get infected upon contact with other infected bacteria.
* You can make bacteria breed on contact. If you've done the previous, it's fun to try different possible outcomes for offspring.
* You can graph the amount of ill/healthy/dead bacteria and see how initial conditions affect the population.

Re: Infection

Posted: Sep 29th, '15, 12:04
by mguzdial
Super cool -- thanks for sharing it!

Question from someone still digging into GP: You trigger updates on receiving "step." How did you know that a "step" message is sent? Is there a list somewhere? I've seen "init" too, and "go," of course.

Re: Infection

Posted: Sep 29th, '15, 13:08
by bromagosa
Thanks, Mark!

The message is sent manually, you can broadcast any message with any arbitrary name by using the [broadcast [message] >] block, which is also variadic and allows you to send data along with the message name, or to specify who you send it to.

These are not like Smalltalk messages though, they are similar in that objects can handle them or ignore them, but they are not (usually) directed to a particular instance, but broadcast to the whole system instead and intercepted only by whoever needs to handle them.

Re: Infection

Posted: Sep 29th, '15, 15:04
by JohnM
There are two special messages sent by GP itself:

go - broadcast when the "go" button is pressed
initialize - invoked on a newly created instance to allow it to initialize itself

Note that initialize is invoked synchronously to allow a new instance to finish initializing itself before it gets added to the stage. That means that an initialize script shouldn't contain a infinite loop or anything that takes a long time to run. See the Dots project for an example of using initialize.

Re: Infection

Posted: Oct 4th, '15, 00:13
by mguzdial
Thank you both! That helps a lot!