Multibrains and Variable Scope

By Myline de Nolia
Copied from ProjectSpark.com

In Project Spark every object can be equipped with several brains.
When you use a variable from any brain, it refers to attributes of the object running the brain.

This small slide summarize various concepts about how multi brain works in project spark:

For example if you do:

Quote:

Logic cube’s brain
WHEN DO [text_variable:myVar] [=] [text:”In the brain”]

Object´s brain:
WHEN [once] DO
…/WHEN DO [text_variable:myVar] [=] [text:”In the brain”]
…/WHEN DO [Add Brain] [object_variable:logicCube]
WHEN DO [say] [text_variable:myVar]

Your object will say “In the brain”.
Now, you may want the scope of you variable to be specific to your brain. In this case you can do:

Quote:

Logic cube’s brain:
WHEN DO [thisBrain][text_variable:myVar] [=] [text:”In the brain”]

Object’s brain:
WHEN [once] DO
…/WHEN DO [text_variable:myVar] [=] [text:”In the object”]
…/WHEN DO [brain_variable:myOtherBrain] [=] [Add Brain] [object_variable:LogicCube]
WHEN DO [say] [var:myVar]
WHEN DO [say] [brain_variable:myOtherBrain][text_variable:myVar]

Now your object will display two sayboxes, one with “In the object” and the other one with “In the brain”.

For those who program, that is very usefull since you can basically use the Brain as a class or a struct which can contains whatever you want.

An important point is that the fields of the brain seem to have to be created from the brain itself. I did not manage to add fields from outside, only to modify the values of existing ones.

Comments are closed.

Website Powered by WordPress.com.

Up ↑

%d bloggers like this: