Object Oriented Programming library

I have created a Snap library to help with OOP (Object Oriented Programming).

<blocks app="Snap! 5.1, http://snap.berkeley.edu" version="1"><block-definition s="%&apos;key&apos; of %&apos;object&apos;" type="reporter" category="other"><header></header><code></code><translations></translations><inputs><input type="%s"></input><input type="%obj"></input></inputs><script><block s="doIf"><block s="reportEquals"><block var="object"/><block s="reportNewList"><list></list></block></block><script><custom-block s="error %txt"><l>key not found in object</l></custom-block></script></block><block s="doIf"><block s="reportEquals"><block var="key"/><block s="reportListItem"><l>1</l><block s="reportListItem"><l>1</l><block var="object"/></block></block></block><script><block s="doReport"><block s="reportListItem"><l>2</l><block s="reportListItem"><l>1</l><block var="object"/></block></block></block></script></block><block s="doReport"><custom-block s="%s of %obj"><block var="key"/><block s="reportCDR"><block var="object"/></block></custom-block></block></script></block-definition><block-definition s="set %&apos;key&apos; of %&apos;object&apos; to %&apos;value&apos;" type="command" category="other"><header></header><code></code><translations></translations><inputs><input type="%s"></input><input type="%obj"></input><input type="%s"></input></inputs><script><block s="doIf"><block s="reportEquals"><block var="object"/><block s="reportNewList"><list></list></block></block><script><custom-block s="error %txt"><l>Key not found in object</l></custom-block></script></block><block s="doIf"><block s="reportEquals"><block var="key"/><block s="reportListItem"><l>1</l><block s="reportListItem"><l>1</l><block var="object"/></block></block></block><script><block s="doReplaceInList"><l>2</l><block s="reportListItem"><l>1</l><block var="object"/></block><block var="value"/></block><block s="doStopThis"><l><option>this block</option></l></block></script></block><custom-block s="set %s of %obj to %s"><block var="key"/><block s="reportCDR"><block var="object"/></block><block var="value"/></custom-block></script></block-definition><block-definition s="error %&apos;msg&apos;" type="command" category="control"><header></header><code></code><translations>pt:lança o erro _&#xD;</translations><inputs><input type="%txt"></input></inputs><script><block s="doRun"><block s="reportJSFunction"><list><l>msg</l></list><l>throw new Error(msg);</l></block><list><block var="msg"/></list></block></script></block-definition><block-definition s="run method %&apos;key&apos; of %&apos;object&apos; with inputs %&apos;inputs&apos;" type="command" category="other"><header></header><code></code><translations></translations><inputs><input type="%s"></input><input type="%obj"></input><input type="%mult%s"></input></inputs><script><block s="doRun"><custom-block s="%s of %obj"><block var="key"/><block var="object"/></custom-block><block s="reportCONS"><block var="object"/><block var="inputs"/></block></block></script></block-definition><block-definition s="call method %&apos;key&apos; of %&apos;object&apos; with inputs %&apos;inputs&apos;" type="reporter" category="other"><header></header><code></code><translations></translations><inputs><input type="%s"></input><input type="%obj"></input><input type="%mult%s"></input></inputs><script><block s="doReport"><block s="evaluate"><custom-block s="%s of %obj"><block var="key"/><block var="object"/></custom-block><block s="reportCONS"><block var="object"/><block var="inputs"/></block></block></block></script></block-definition><block-definition s="cat %&apos;name&apos;" type="reporter" category="other"><header></header><code></code><translations></translations><inputs><input type="%txt">Bob</input></inputs><script><block s="doReport"><block s="reportNewList"><list><block s="reportNewList"><list><l>&lt;CLASSNAME&gt;</l><l>cat</l></list></block><block s="reportNewList"><list><l>name</l><block var="name"/></list></block><block s="reportNewList"><list><l>alive</l><block s="reportBoolean"><l><bool>true</bool></l></block></list></block><block s="reportNewList"><list><l>meow</l><block s="reifyScript"><script><block s="doIf"><custom-block s="%s of %obj"><l>alive</l><block var="self"/></custom-block><script><block s="doSayFor"><block s="reportJoinWords"><list><custom-block s="%s of %obj"><l>name</l><block var="self"/></custom-block><l>: Meow!</l></list></block><l>2</l></block></script></block></script><list><l>self</l></list></block></list></block><block s="reportNewList"><list><l>sleep</l><block s="reifyScript"><script><block s="doIf"><custom-block s="%s of %obj"><l>alive</l><block var="self"/></custom-block><script><block s="doSayFor"><block s="reportJoinWords"><list><custom-block s="%s of %obj"><l>name</l><block var="self"/></custom-block><l> slept for </l><block var="hours"/><l> hours</l></list></block><l>2</l></block></script></block></script><list><l>self</l><l>hours</l></list></block></list></block><block s="reportNewList"><list><l>die</l><block s="reifyScript"><script><block s="doIf"><custom-block s="%s of %obj"><l>alive</l><block var="self"/></custom-block><script><custom-block s="set %s of %obj to %s"><l>alive</l><block var="self"/><block s="reportBoolean"><l><bool>false</bool></l></block></custom-block></script></block></script><list><l>self</l></list></block></list></block></list></block></block></script></block-definition><block-definition s="new empty %&apos;class&apos;" type="reporter" category="other"><header></header><code></code><translations></translations><inputs><input type="%s">cat</input></inputs><script><block s="doReport"><block s="reportNewList"><list><block s="reportNewList"><list><l>&lt;CLASSNAME&gt;</l><block var="class"/></list></block></list></block></block></script></block-definition><block-definition s="add %&apos;key&apos; = %&apos;value&apos; to %&apos;object&apos;" type="command" category="other"><header></header><code></code><translations></translations><inputs><input type="%s"></input><input type="%s"></input><input type="%obj"></input></inputs><script><block s="doAddToList"><block s="reportNewList"><list><block var="key"/><block var="value"/></list></block><block var="object"/></block></script></block-definition></blocks>

It comes with some blocks to create classes and an already defined class called "cat", which has a name, whether it's alive and 3 methods.

Hi!


:~P

Cats have nine lives

They only have seven lives where I'm from :wink:

How do I import a library with its HTML XML?

Ah, this is actually XML. It's the format Snap projects and blocks and stuff take when exported. Anyways, You'll want to paste the text into a text editor, then save it as an XML file. After that, you can import it into Snap.

OK
Now I know the difference between HTML and XML.

I saved the text file as oop.xml.txt and used this website to download oop.xml.xml. When I import oop.xml.xml, a variable called oop is created with the value being some XML, but when I import oop.xml.txt, the blocks appear like they should.

Just save it as oop.xml. Why add a second extension? :thinking:

I typed oop.xml as the title of the Google Doc, so oop.xml.txt was downloaded. With the converter website, oop.xml.xml was downloaded.
Another thing: doing the same thing with the XML for this library only created a variable either with the XML or TXT file.

Curiosity

Wait, I'm telling a list to do something. I should have used run instead of tell.

If you tell Google that the filename is just "oop" with no extension, then the right thing will happen.

By the way, methods are supposed to have a first argument called "self" which references the object itself.