Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Turing Chat - Emotion Problem
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tycoon




PostPosted: Fri Feb 17, 2006 10:35 pm   Post subject: Turing Chat - Emotion Problem

NOTE: This was a chat program I found on the forums and to get more involved with Turing I am changing it around to my needs.

The Problem: I want the user to be able to enter emotions and as you can see I coded Smile to be a smiley face (found here) BUT I cannot: a) have it carried over to the other users window, b) I cannot figure out a way to have it coded on the line the user is currently 1) viewing, 2) typing on - Right now it will appear in the bottom left hand corner ( or 0 0 )
Can anyone help me?

code:
var stream : int := 0 % Used for sending data
var msgBack : string % The message that gets sent back and forth
var address : string % IP address for each computer
var message : string  % Message that you send
var status : int % Status host/client
var name : string % Screen name

%%%%%%%%%%%%% all the emotions %%%%%%%%%%%%%%%%%%%%%%%%
var happy : int := Pic.FileNew ("C:/emotions/smile.bmp")
var sad : int := Pic.FileNew ("C:/emotions/sad.bmp")

const PORT := 5555 % Port to connect through

put "Welcome to Turing chat!"
put ""
put "Please enter your chat name"
get name % Input Screen name
put ""
loop
    put name, " what would you like to do?"
    put "1: Host a session"
    put "2: Join a session"
    get status

    if status = 1 then
        put "Waiting for a user to join...."
        stream := Net.WaitForConnection (PORT, address) % Wait for a user to connect

    elsif status = 2 then
        put "What is the IP of the computer you want to connect to?"
        get address
        stream := Net.OpenConnection (address, PORT) % Connect to the IP inputted

    else % If 1 or 2 is not chosen, choice will be looped
        put "Please choose 1 or 2"
        cls
    end if

    exit when status = 1 % Exits when 'status' is 1 ..
    exit when status = 2 % or when 'status' is 2 so it can continue
end loop
cls
put "Connected to ", address

loop
    if hasch then % If key pressed
        color (red)
        put name, ": " ..
        get message : *     % Store all input in varariable 'message' when enter is pressed
        put : stream, name, ": ", message       % Send the message , alone with screen name, over the stream

        if message = "cls" then
            cls
        end if

        %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
        % Image Codes for users use
        if message = ":)" then
            Pic.Draw (happy, 0, 0, picCopy)
        end if
        if message = ":(" then
            Pic.Draw (sad, 0, 0, picCopy)
        end if

        exit when message = "quit"      % To exit the chat session
    end if
    if Net.LineAvailable (stream) then      % If a line of text has been sent
        get : stream, msgBack : *        % Grab the line of text, if one is waiting
        color (blue)
        put msgBack     % Print the received message to the screen

    end if
end loop
put "Connection has been terminated...."


Thank you for the origonal code and in advace for the help

Tycoon ^_^
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Sat Feb 18, 2006 10:58 am   Post subject: (No subject)

Well yes it's going to appear at (0,0) since that's where you've told it to appear Rolling Eyes .

Tycoon wrote:

code:

Pic.Draw (happy, 0, 0, picCopy)



You'll want to change those 0's to variables instead, then you'll need to figure out where the typing is currently occuring, and draw accordingly.
If you're using pure text, you can use the 'whatcol' and 'whatrow' functions - rather nifty they are! - to get your bearings.
As a side note, this really isn't the sort of programme to use to orient yourself with Turing. Looking through the Tutorials might be a better idea.
Another note: Yes this is from [Turing Source Code] but it would still be polite to acredit this code to its original author...you know, one of those "based on the code of..." type things.
Cervantes




PostPosted: Sat Feb 18, 2006 11:09 am   Post subject: (No subject)

The text you type should be sent to the other computer without rendering it. That is, if I type "Hey Tycoon! :)" it should be sent through to you as is, without changing the ":)" to a smilie graphic.

You should have a render_text procedure, or some such, to search through the text and change all emoticons to their appropriate graphics. It should also draw the text in the appropriate location. The server and client should run this procedure each time a new message appears, either a message from themselves or from the other one.

Also, you could use a less invasive method to get input. The "if hasch then" is a good start, but it only works well enough with getch. Sticking a get inside the "if hasch then" will only make getting the first character painless; you're still going to have to wait to get the rest of the characters. I suggest you use a text field to get user input. This could be a Turing's GUI Textfield, or you could try making one of your own. Alternatively, you could use mine[/shameless plug].
MysticVegeta




PostPosted: Sat Feb 18, 2006 4:20 pm   Post subject: (No subject)

Hmm well for the smilies, you can always export all the words into a flex array and check for emoticons... Its somewhere on the source code I posted a String.split(x:string) module...
Cervantes




PostPosted: Sat Feb 18, 2006 4:49 pm   Post subject: (No subject)

MysticVegeta wrote:
Hmm well for the smilies, you can always export all the words into a flex array and check for emoticons... Its somewhere on the source code I posted a String.split(x:string) module...

How does your String.split function return a flexible array? So far as I know, that's not permitted.

Why split it into a flexible array? You've got the message as a string, and you can do plenty of string manipulation on that message without splitting it up into a flexy array. Though it would work, it takes unnecessary memory to store the (essentially) same message again, as a flexy array.

I've searched around for this much fabled String module of yours, and have yet to find anything. The closest I got was a "stringSplit" function, that is hugely redundant (you could take out those first two for loops entirely). The only string module I've found is my own. Confused
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: