7 Distant running commands

We already know how to send and receive the messages. So far we were sending only simple messages, which we printed to the text screen or the turtle printed them to the graphic screen. In this chapter we will learn how to send the messages, which the turtle or Imagine can run.

1. Connect two or more Imagines (either locally or through the Internet).

If we know, that other participants will send only instructions for the turtle, we can progress in next steps.

2. Specify the onReceive event as t1'run message in Change net1 dialogue box in all Imagines
onReceive event
or by net1'setEvent "onReceive [t1'run message] in command line.

3. Now, we can write in command line instructions, which the turtle can run, for example in one Imagine

? net1'send [][setPc "red setPw 4 repeat 4 [fd 50 rt 90]]
? net1'send [][rt 180]
? net1'send [][setPc "blue setPw 6 repeat 4 [fd 50 rt 90]]

in other Imagine

? net1'send [][setPw 3]
? net1'send [][repeat 8 [setPc any fd 50 point 15 bk 40 rt 45]]

run

If we do not know, what kind of messages other participant will send, we can specify the onReceive event as run message or we must progress in next steps.

Note: This setting allows other users to send instructions, which can erase your object, procedures, files…

4. Check the RunEnabled setting in Change net1 dialogue box in all Imagines
runEnabled
or type next instruction to the command line:

  • net1'setRunEnabled "true
This setting allows or does not allow sending list of instructions using sendRun. This list of instructions will be run directly in the Imagine environment.

5. Now, we can type in command line instructions with list of instructions, for example:

? net1'sendRun [][new "Turtle [name myTurtle pos [-100 -50]]]
? net1'sendRun [][myTurtle'repeat 5 [pu setPc [255 any 0] setPw any setPos any pd repeat 6 [fd 15 rt 120 fd 15 lt 60]]]

sendrun

We can use both send and sendRun commands.

6. Specify the onReceive event for net1 object as:

  • t1'label message t1'back 20

Then set the turtle (position, pen - pu, colour, width…).

7. Type in command line for example next instructions:

? net1'send [][This is a square.]
? net1'sendRun [][new "Turtle [name square pos [100 50] pc red pw 4]]
? net1'sendRun [][square'repeat 4 [fd 20 rt 90]]

send sendrun

Conclusion

We learned how to send messages, which Imagine or turtle in other Imagine can run. We must correctly set onReceive event and then use send command. This way we can send instruction for one object, which defined our participant. Or we must set RunEnabled setting on true and then use sendRun command. Imagine of other participant runs sent commands automatically.