Welcome to Phrogram Sign in | Join | Help
in Search


Phrogram Talk - AutoChat example

Last post 12-18-2007, 2:06 PM by LFS. 0 replies.
Sort Posts: Previous Next
  •  12-18-2007, 2:06 PM 5748

    Phrogram Talk - AutoChat example

    Writing a chat phrogram to talk to a buddy online is easy using the Phrogram Talk add-in library. The add-in library includes an AutoChat mode that will handle the sending and receiving of chat messages while displaying the conversation in a separate window. The example code included below shows how to use the AutoChat feature.

    To set up your system to see both the local and remote sides of a chat session, you need to use two separate accounts on the same chat server. For more details on how to set that up read the Set-up for Program Testing section in the PhrogramTalk User Guide. For an example of how you might incorporate PhrogramTalk into an online game, download the WordGuess source code.

    Program AutoChatDemo
    	
         Define client As ChatClient
         Define buddy As ChatContact 
    	
    	Method Main()
    		
    		// Set up screen
    		HideToolbar()
    		SetScreensize(200, 100)
    		
    		// Set AutoChat mode
    		Client.AutoChat = True
    		
    		// Ask the user to sign in
    		While Not client.IsConnected 
    			If Not client.Login(True) Then
    				If Not Confirm("Log in failed.\nTry again?", "Log In Error") Then
    					Return
    				End If
    			End If
    		End While
    		
    		// Select a buddy
    		While Not Buddy.Online 
    			buddy = client.SelectContact("Select your buddy", False, False)
    			If Not buddy.Online Then
    				If Not Confirm("Contact not online.\nSelect again?", "Connection Failed") Then
    					Return
    				End If
    			End If
    		End While
    		
    		// Connect to buddy (opens chat window on remote computer)
    		Buddy.SendMessage(Client.UserName + " is online.")
    		
    		// Send ID to program window
    		Printline("I am " + Client.UserName)
    		PrintLine("Talking to " + Buddy.DisplayName )
    		
    		// Keep alive for chatting
    		While True
    			Delay(50)
    			DoEvents()
    		End While
    
    	End Method
    
    End Program
    Filed under: , , , ,
View as RSS news feed in XML