wiki:Python Quagents Client

Python Quagents Client

Client.py:

This file contains the Client class. Clients connect to the server on port 6000. Each client stores information about it's name, id, commandid, etc. Calling the ready() function spawn a quagent.
NOTE: Sometimes calling ready() too fast will not spawn a quagent and the program will be stuck waiting for a response from the server. Calling setName() before ready() usually avoids this problem.

Command.py

This file contains the Command class and the individual command classes that inherit from the Command class. Each individual command takes in a different number of parameters and has a unique opcode. Each command must be attached to a client which is done by calling the setExecuter() function. The command can then be executed by calling execute().
NOTE: Executing multiple commands too fast causes the received data to get screwed up at times so the program sleeps for a brief period after each command.

Example Code

Writing a script to control a quagent is very simple. See the following example.

# Main.py
import client
import command
import time

agent = client.Client("127.0.0.1")	# Creates a quagent
agent.setName('Quagent')
agent.ready()				# Spawn

# Give commands to quagent by creating the command object and setting the quagent as the executor
fo = command.Follow('n')	
fo.setExecutor(agent)
fo.execute()
pu = command.PickUp('n')
pu.setExecutor(agent)
pu.execute()
ci = command.CheckInventory('n')	
ci.setExecutor(agent)
ci.execute()
pd = command.PutDown(0, 20, 'n')	# The parameters correspond to protocolzero. The last parameter is always the priority
pd.setExecutor(agent)
pd.execute()
ci.execute()
Last modified 13 years ago Last modified on Aug 24, 2011 2:42:58 PM