
-----------------------------------
templest
Fri Oct 22, 2004 4:31 pm

New Chat Program (with errors). Opening Files = Crash.
-----------------------------------
I've been staring at this for thirty minutes trying to find out wtf is wrong with it. It opens the file perfectly the first time, gets and sets the username to what's in the "config.ini". But when I try to re-open the file in a process for changing the username, it gives me an "Invalid StreamNumber" error. :mad:

Ideas?

%juice-box
%v0.1
%by: templest d azmitia

import GUI
View.Set ("graphics:400;300,title:juice-box v0.1,nobuttonbar")
GUI.SetBackgroundColor (gray)

var input, output, font, font_bold, dummy_buffer, connection, file : int
var dummy_buffer_str, name : string

var port_list : array 1 .. 120 of int
font := Font.New ("verdana:8")
font_bold := Font.New ("verdana:8:bold")

dummy_buffer := 7200
for i : 1 .. 120
    port_list (i) := dummy_buffer
    dummy_buffer := dummy_buffer + 1
end for

name := "user"
proc getname
    open : file, "config.ini", get
    loop
        exit when eof (file)
        get : file, dummy_buffer_str : *
        if length (dummy_buffer_str) > 5 and dummy_buffer_str (1 .. 5) = "name:" then
            name := dummy_buffer_str (6 .. *)
        end if
    end loop
    close : file
end getname
getname

proc changename (new_name : string)
    dummy_buffer := 1

    open : file, "config.ini", put, mod, seek
    loop
        exit when eof (file)
        get : file, dummy_buffer_str : *
        if length (dummy_buffer_str) > 5 and dummy_buffer_str (1 .. 5) = "name:" then
            seek : file, (dummy_buffer)
            put : file, "name:" + new_name
            getname
            exit
        end if
        dummy_buffer := dummy_buffer + 1
    end loop

    close : file
end changename

connection := 0
proc connect (address : string)
    GUI.AddLine (output, "** Please wait while connecting... **")
    for r : 1 .. 120
        connection := Net.OpenConnection (address, port_list (r))
        if connection > 0 then
            exit
        end if
    end for

    if connection < 0 then
        %connection not established msg goes here
        GUI.AddLine (output, "** Connection to '" + address + "' failed **")
        GUI.AddLine (output, Error.LastMsg)
        GUI.AddLine (output, "")
    else
        %connection establish msg goes here
        GUI.AddLine (output, "** Connection to '" + address + "' has been established**")
    end if
end connect

proc input_string (msg : string)
    %processing of input goes in here
    if msg = "!quit" then
        GUI.Quit
    elsif length (msg) > 9 and msg (1 .. 8) = "!connect" then
        dummy_buffer_str := msg (10 .. *)
        connect (dummy_buffer_str)
    elsif length (msg) > 6 and msg (1 .. 5) = "!name" then
        dummy_buffer_str := msg (7 .. *)
        changename (dummy_buffer_str)
    else
        GUI.AddLine (output, name + " says: " + msg)
        if connection > 0 then
            put : connection, name + " says: " + msg
        end if
    end if
    GUI.SetText (input, "")
end input_string

input := GUI.CreateTextFieldFull (10, 10, maxx - 20, "", input_string, GUI.INDENT, font, 0)
output := GUI.CreateTextBoxFull (10, 35, maxx - 20, maxy - 45, GUI.INDENT, font)

loop
    exit when GUI.ProcessEvent
end loop


-----------------------------------
templest
Fri Oct 22, 2004 6:49 pm


-----------------------------------
Anyone? :cry:

-----------------------------------
Mazer
Fri Oct 22, 2004 7:54 pm


-----------------------------------
I assume you mean when you type "!name xxxxx", right? Sorry, I can't find a problem with your code, I'm thinking turing is just... well, turing.

-----------------------------------
templest
Fri Oct 22, 2004 10:06 pm


-----------------------------------
I assume you mean when you type "!name xxxxx", right? Sorry, I can't find a problem with your code, I'm thinking turing is just... well, turing.

Yes, and I'm begining to think: Yes. Goddamnit, I guess I'm going to start looking for some "C" PDFs in the very near future. I can't wait until second semester. Damn patience! In fact, damn it all! Damn it all to hell!

-----------------------------------
Tony
Fri Oct 22, 2004 10:23 pm


-----------------------------------

put : file, "name:" + new_name
            getname  