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

Username:   Password: 
 RegisterRegister   
 Detection And opening files.
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
d2bb




PostPosted: Tue Apr 17, 2007 10:11 am   Post subject: Detection And opening files.

well first i'd just like to know what cmd to use to open a file (Open a game file, so it runs)






Second Question:

Im just making a simple bot, that mimics a users. (Bot can do exact same stuff as human, like: Heal, Attack, So on..)


For example:

If your player has 100 life, and ud like the bot to heal you if you lose health, how would i detect that the life has decreased.


(my explonation may be sketchy)
Sponsor
Sponsor
Sponsor
sponsor
Clayton




PostPosted: Tue Apr 17, 2007 2:48 pm   Post subject: RE:Detection And opening files.

What type of file do you mean? If you mean a text file that you can open and extract information from, then you'll need to look into File I/O in the Turing Walkthrough. If you mean files such as .exes, then look into Sys.Exec()

To detect if life decreases you'll need some sort of variable to keep track of max life, as well as current life.
Carey




PostPosted: Wed Apr 18, 2007 8:47 am   Post subject: Re: Detection And opening files.

Turing:
function translate (dir : string) : string %converts all "/"s to "\"s
    var path := ""
    for i : 1 .. length (dir)  %used for counting substrings
        if index (dir (i), "/") = 0 then  %if the substring is not "/"
            path += dir (i)  % add the current letter to the string
        else  %if the substring is "/"
            path += "\\"  %add a "\" the the string
        end if
    end for
    result path  %return the path
end translate

procedure runFile (path : string)
    if not Sys.Exec (path) then  %if the path has spaces this won't work
        if not Sys.Exec ("C:/WINDOWS/explorer.exe " + translate (path)) then %use explorer to open the file
        end if
    end if
end runFile

runFile ("notepad.exe") %has to be full path unless the file is in the current dir or is in the windows dir(notepad.exe)


That should work for opening any file. If you use a path with spaces the file will open with explorer and will sometimes give the option to save or open the file. This is because it opens the files that it doesnt know what to do with with IE.
Daetyrnis




PostPosted: Wed Apr 18, 2007 3:33 pm   Post subject: Re: Detection And opening files.

Rather than...
Turing:
if index (dir (i), "/") = 0 then

...wouldn't...
Turing:
if dir (i) ~= "/" then

...be more efficient?
ericfourfour




PostPosted: Wed Apr 18, 2007 6:30 pm   Post subject: RE:Detection And opening files.

That is true Daetyrnis.

Carey, you should consider making the translate function recursive to reduce its size and possibly increase the efficiency.
d2bb




PostPosted: Tue May 08, 2007 2:27 pm   Post subject: RE:Detection And opening files.

yea, what if there is spaces in the dir. lol.

ill play around with this code for a while try 2 c if i can figure out what u wrote Razz

thx for help Smile
Carey




PostPosted: Wed May 09, 2007 8:47 am   Post subject: Re: Detection And opening files.

How would i make the translate funtion recursive and how would it make it more efficiant? wouldnt you still have to add all the letters to another string that returns?
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  [ 7 Posts ]
Jump to:   


Style:  
Search: