PDA

View Full Version : creating portal script


zeckblad
03-31-2008, 10:05 AM
Having a great time using this product but I am stuck on a simple problem for creating talking from a node back to portal. I see that rpc("\x00\x00\x01",... is used to call a portal script.

How do I create or modify the portal script?

kbanks
03-31-2008, 10:58 AM
To create a brand new script, click on the New Script button on the upper toolbar. (This is shown in section 8 of the SNAP Reference Manual)

This will open up a script editing window, which will have its own toolbar.

Define the functions you need in the script, in standard Python. For example:

def test(text):
print "some node says ",text # indent this line!

(The print statement above should be indented, but the forum is not showing it exactly as I enter it)

When you click on the Save As button (looks like a diskette with a pencil in front of it), you will be prompted for the name to give the script.

In this case, since we are creating a Portal script, it would be best to save it in the ..\Portal directory, not in the ..\Portal\snappyImages directory.

To load the script into Portal, click on the Change Portal Base File button on the upper toolbar. A "file chooser" dialog box will appear. Browse to the file you just created.

To have Portal remember to use this script next time you start it, click on the Save All button in the upper toolbar.

With the script loaded into Portal, the functions within it become available to be invoked by the user (see section "Node Info" of section 6 of the SNAP Reference Manual). These same functions can also be invoked by remote nodes. Using the same example above:

# this line of code would be in the SNAPpy script of a remote node
rpc("\x00\x00\x01", 'test', 'Hello, world!")