Jump to content

Help make this script faster


Recommended Posts

okay. I'm making a chatting program for my network. Right now, I'm using ini's to save the chat log to the network and to read the chat log. It is currently set up to check the ini file every 1/2 a second but it ramdomly will get very laggy and can take up to 15 seconds to display a message. I really don't know why this is happening. Any help about fixing that or any other bugs you see are appreciated.

#include <GUIConstants.au3>
#Include <Date.au3>

#NoTrayIcon



HotKeySet("^i","special")
;IniWrite("c:\walls\location.ini","location","location","")
$location = IniRead(@ScriptDir & "\location.ini","location","location",@ScriptDir);"c:"
$name = "\chat.ini"
$msg2 = ""
$bg = ""
$exit = ""
$refresh = ""
$set = ""
$active = ""
$effect = ""
$name2 = ""
;If IsAdmin() Then Exit

GUICreate("Talk Alpha",800,600,0,0)
$start = GUICtrlCreateButton("Start Chat",20,20,75,30)
$channel = GUICtrlCreateInput("Channel",115,25,75,20)
$input = GUICtrlCreateInput("",20,100,760,430,"0x00201004")
$msg3 = GUICtrlCreateInput("",20,550,670,20)
$send = GUICtrlCreateButton("Send",710,545,50,30)


GUISetState()



While 1
    $msg = GUIGetMsg()
    If $msg = $GUI_EVENT_CLOSE and WinActive("Talk Alpha") then exit1()
    If $msg = $start Then start()
    If $msg = $exit Then WinClose("Specialness...")
    If $msg = $refresh Then
        $list = IniRead($location & $name,"Names","Users","")
        $list = StringReplace($list,"¡",@crlf)
        GUICtrlSetData($active,$list)
    EndIf
    If $msg = $set Then change()
    sleep(100)
WEnd

Func start()
    $count = 0
    $channel = GUICtrlRead($channel)
    $users = IniRead($location & $name,"Names","Users","")
    $chans = IniRead($location & $name,"Names","Users and Channels","")
    IniWrite($location & $name,"Names","Users", @UserName & "¡" & $users)
    IniWrite($location & $name,"Names","Users and Channels", @UserName & ": "  & $channel& "¡" & $chans)
    HotKeySet("{enter}","enter")
    While 1
        $count = $count + 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE and WinActive("Talk Alpha") then exit1()
        If $count = 10 Then
            $talk = IniRead($location & $name,"Chat",$channel,"")
            $talk1 = StringReplace($talk,"¡",@CRLF)
            GUICtrlSetData(5,$talk1,"")
            $count = 0
            changewall()
        EndIf
        If $msg = $send Then sendmsg()
        If $msg = $exit Then WinClose("Specialness...")
        If $msg = $refresh Then
            $list = IniRead($location & $name,"Names","Users","")
            $list = StringReplace($list,"¡",@crlf)
            GUICtrlSetData($active,$list)
        EndIf
        If $msg = $set Then change()
        sleep(50)
    WEnd
EndFunc

Func exit1()
    $users = IniRead($location & $name,"Names","Users","")
    $chans = IniRead($location & $name,"Names","Users and Channels","")
    $users = StringReplace($users,@UserName & "¡","")
    $chans = StringReplace($chans,@UserName & ": "  & $channel& "¡","")
    IniWrite($location & $name,"Names","Users", $users)
    IniWrite($location & $name,"Names","Users and Channels", $chans)
    If $users = "" Or $chans = "" Then IniDelete($location & $name,"Chat",$channel)
    Exit
EndFunc

Func enter()
    If WinActive("Talk Alpha") Then 
        sendmsg()
    Else
        HotKeySet("{enter}")
        Send("{enter}")
        HotKeySet("{enter}","enter")
    EndIf
EndFunc

Func sendmsg()
    $msg2 = GUICtrlRead($msg3)
    $msg_old = IniRead($location & $name,"Chat",$channel,"")
    IniWrite($location & $name,"Chat",$channel, @UserName & ": " & _NowTime(5) & " -- " & $msg2 & "¡" & $msg_old)
    GUICtrlSetData($msg3,"")
EndFunc

that is a shortened version of my code. I'll paste the full version if anyone things its needed but I'm not having issues with that part.

Link to comment
Share on other sites

okay but still odd things...

Func start()
    $whileile = 0
    $count = 0
    $channel = GUICtrlRead($channel)
    $users = IniRead($location & $name,"Names","Users","")
    $chans = IniRead($location & $name,"Names","Users and Channels","")
    IniWrite($location & $name,"Names","Users", @UserName & "¡" & $users)
    IniWrite($location & $name,"Names","Users and Channels", @UserName & ": "  & $channel& "¡" & $chans)
    HotKeySet("{enter}","enter")
    While 1
        $count = $count + 1
        $msg = GUIGetMsg()
        If $msg = $GUI_EVENT_CLOSE and WinActive("Talk Alpha") then exit1()
        ;If $count = 2 Then
            MsgBox(0,"","")
            $talk = IniRead($location & $name,"Chat",$channel,"")
            $talk1 = StringReplace($talk,"¡",@CRLF)
            GUICtrlSetData(5,$talk1,"")
            $count = 0
            changewall()
        ;EndIf
        If $msg = $send Then sendmsg()
        If $msg = $exit Then WinClose("Specialness...")
        If $msg = $refresh Then
            $list = IniRead($location & $name,"Names","Users","")
            $list = StringReplace($list,"¡",@crlf)
            GUICtrlSetData($active,$list)
        EndIf
        If $msg = $set Then change()
        ;sleep(50)
    WEnd
EndFunc

for some odd reason... the message boxes aren't poping up steadily. It will pop up somewhere between 4-10 times in very quick sucession (basically instantly) but then... it randomly takes a break of 3-15 seconds... i have no idea why. does anyone??

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...