Heya, I have an object - draft_text
I want to be included within an information box that pops up, how would I do this?
This is so when a user types a message it appears within that box
Also, how would I get the information box to follow an avatar around the screen?
The code i am using to create a networked chat box is below
Thanks in advance, FC
Code:
sent_message.visible(0)
typing_message.visible(0)
#Use a prompt to ask the user the network name of the other computer.
target_machine = viz.input('Enter the name of the other machine').upper()
#Add a mailbox from which to send messages. This is your outbox.
target_mailbox = viz.addNetwork(target_machine)
#Start with sending_text as a blank space.
out_text = ''
def SendData():
#Retrieve current transform of viewpoint
mat = viz.MainView.getMatrix()
#Apply offsets so duck model matches viewpoint
mat.preEuler(180,0,0)
mat.preTrans(0,-1,0)
#Send position/rotation to target network object
target_mailbox.send(quat=mat.getQuat(),pos=mat.getPosition(),message=out_text)
# Start a timer that sends out data over the network every frame
vizact.ontimer(0,SendData)
# Listens for any incomming messages
def onNetwork(e):
avatar.setPosition(e.pos)
avatar.setQuat(e.quat)
inbox.message(e.message)
# Register network to listen from incoming messages
viz.callback(viz.NETWORK_EVENT, onNetwork)
#Create a variable for the draft of the outgoing message.
draft_text = ' '
def mykeyboard(key):
global out_text, draft_text
#If the length of the key is 1 then
#add the character to the string.
if draft_text == '':
sent_message.visible(0)
typing_message.visible(0)
if len(key) == 1:
draft_text += key
sent_message.visible(0)
typing_message.visible(1)
#If the key is a character return, end the line, make the
#outgoing message equal to the draft message, and set the draft equal
# to a blank space.
elif key == viz.KEY_RETURN:
out_text = draft_text
sent_message.visible(1)
typing_message.visible(0)
#If the key is the backspace key then remove the last character of the string.
elif key == viz.KEY_BACKSPACE:
draft_text = draft_text[:-1]
#Update the input text field so that you can see what you're typing.
outbox.message(draft_text)
print draft_text