Yoko

All sides of Injection
It is currently 2025-12-22 17:43:44

All times are UTC+02:00




Post new topic  Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Another question
PostPosted: 2005-05-09 00:07:43 
Offline

Joined: 2005-05-07 01:34:07
Posts: 6
I am working on this script to macro my carpentry skill. The script works but there remain a little problem :

Code:
sub main()

Var Treetype
Var Treex=0
Var Treey=0
Var Treez=0
Var f=file("records.txt")

repeat:

f.Open()

beginlumberjack:

If NOT f.EOF() Then
   Treetype=f.ReadNumber()
   Treex=f.ReadNumber()
   Treey=f.ReadNumber()
   Treez=f.ReadNumber()
   UO.Print("Deplacement vers " + str(Treex) + ", " + str(Treey))
Else
   goto doitagain
Endif


gotoxy(treex,treey,2)
gotoxy(treex,treey,2)
gotoxy(treex,treey,2)

beginchop:

UO.DeleteJournal()

UO.WaitTargetTile(STR(Treetype),STR(Treex),STR(Treey),STR(Treez))
UO.FindType(0x0F49,0x0000,2)
UO.UseObject("finditem")

UO.Print("Buchage...")

while NOT UO.InJournal("You put the Buches") AND NOT UO.InJournal("Vous abimez l'arbre") AND NOT UO.InJournal("There are no logs") AND NOT UO.InJournal("It appears")
   wait(500)
wend

UO.Print("...fin du buchage")

If UO.InJournal("Hetre") then
UO.FindType(0x1bdd,0x05DE,2)
UO.Drop("0",0,0,0,"finditem")
UO.Print("Type de bois ininterressant.")
goto beginlumberjack
Endif

If UO.InJournal("Chene") then
UO.FindType(0x1bdd,0x0974,2)
UO.Drop("0",0,0,0,"finditem")
UO.Print("Type de bois ininterressant.")
goto beginlumberjack
Endif

If UO.InJournal("Pin") then
UO.FindType(0x1bdd,0x03F1,2)
UO.Drop("0",0,0,0,"finditem")
UO.Print("Type de bois ininterressant.")
goto beginlumberjack
Endif

If UO.InJournal("Orme") then
UO.FindType(0x1bdd,0x008D,2)
UO.Drop("0",0,0,0,"finditem")
UO.Print("Type de bois ininterressant.")
goto beginlumberjack
Endif

If UO.Weight>=500 then
   goto endlumberjack
Endif

If UO.InJournal("There are no logs here to chop.") OR UO.InJournal("It appears") then
   UO.Print("Arbre suivant...")
   goto beginlumberjack
Else
   UO.Print("Il en reste...")
   goto beginchop
Endif

endlumberjack:

UO.Print("Fin du programme de lumberjacking.")

UO.Print("Session epees en bois !")

Var nb_epees
Var loop=1

UO.Exec("automenu Bois Armes")
UO.Exec("automenu Armes Epee")
UO.DeleteJournal()
While loop>=1
   UO.Exec("useobject 0x400bd761")
   UO.Print("Fabrication...")
   UO.DeleteJournal()
   while NOT UO.InJournal("You put the Epee") AND NOT UO.InJournal("Vous n'arrivez pas") AND NOT UO.InJournal("You can't make")
      wait(500)
   wend
   UO.FindType(0x1bdd,0x0000,2)
   loop=(UO.GetQuantity("finditem"))
   UO.Print("Il me reste " +str(loop)+ " buches.")

wend
UO.Exec("cancelmenu")

UO.Print("Delestage...")

UO.FindType(0x0F5E,0x0728,2)
nb_epees=UO.FindCount()

while nb_epees<>0
   UO.FindType(0x0F5E,0x0728,2)
   nb_epees=UO.FindCount()
   UO.Drop("0",0,0,0,"finditem")
   Wait(500)
   UO.Print("Il reste : " + str(nb_epees) + " a droper")
wend

doitagain:

If f.EOF() Then
   f.Close()
   UO.Print("Session buchage !")
   gotoxy(1967,1659,0)
   gotoxy(1967,1697,0)
   gotoxy(1908,1756,0)
   gotoxy(1864,1795,0)
   goto repeat
Else
   goto beginlumberjack
Endif

end sub


When the script arrives at the end of the following code, it returns a parse error and stop. I absolutely don't know why. Does a file can't be opened twice in one script ?
Code:
If f.EOF() Then
   f.Close()
   UO.Print("Session buchage !")
   gotoxy(1967,1659,0)
   gotoxy(1967,1697,0)
   gotoxy(1908,1756,0)
   gotoxy(1864,1795,0)
   goto repeat


Top
   
 Post subject:
PostPosted: 2005-05-09 08:59:33 
Offline
Expert!
User avatar

Joined: 2005-04-23 10:19:43
Posts: 388
Hmm... i can see repeat on beginning but i can see no until.
File can be opened as much as you want, but every time you open it it must be closed before opened again.


Top
   
 Post subject:
PostPosted: 2005-05-09 15:12:53 
Offline

Joined: 2005-05-07 01:34:07
Posts: 6
Oups, using repeat as a label wasn't a good idea :lol:

But it doesn't work, I got an "runtime error, invalid file" when it come back at the "f.Open()" instruction...


Top
   
 Post subject:
PostPosted: 2005-05-09 16:51:28 
Offline
Expert!
User avatar

Joined: 2005-04-23 10:19:43
Posts: 388
Problem is that you should use abslute path to the file. Like "C:\Test.txt".


Top
   
 Post subject:
PostPosted: 2005-05-09 18:12:58 
Offline

Joined: 2005-05-07 01:34:07
Posts: 6
I didn't explained the problem well...
The script works prefectly one time, but when arrived at the end of file and coming back at the begining, its hangs on the f.open() instruction and send the "runtime error, invalid file". However, i'm sure that the f.close() instruction has been executed.

I've tried to modify the path to an absolute or relative, it changed nothing.


Top
   
 Post subject:
PostPosted: 2005-05-09 18:29:37 
Offline
Expert!
User avatar

Joined: 2005-04-23 10:19:43
Posts: 388
Try this way:
Code:
var f
<loop start>
f=file('filename')
f.Open()
......
f.Close()
<loop end>


I mean to put f=file('filename') definition into the loop.


Top
   
 Post subject:
PostPosted: 2005-05-09 18:30:58 
Offline
Expert!
User avatar

Joined: 2005-04-23 10:19:43
Posts: 388
And, btw, why do you read that file every loop? Cant you read it once into the array and then use it? I think it would be much easyer and give your hard drive a little more rest :D.


Top
   
 Post subject:
PostPosted: 2005-05-10 02:20:28 
Offline

Joined: 2005-05-07 01:34:07
Posts: 6
I want to loop because the file is kinda short and I want the script running 24/7/365 :lol:

But your previous answer was right, It now works perfectly.
Thanks for your help !


Top
   
 Post subject:
PostPosted: 2005-05-10 07:45:48 
Offline
Expert!
User avatar

Joined: 2005-04-23 10:19:43
Posts: 388
I didnt mean about the looping, i meant about the reading from file.
Cant you do it like this:

Code:
dim ArrX[100],ArrY[100]
<Read data from file to array>
<loop start>
  <work with that ARRAY>
<loop end>


I think it would work maybe a little bit faster after that ;D.


Top
   
 Post subject:
PostPosted: 2005-05-10 15:04:02 
Offline

Joined: 2005-05-07 01:34:07
Posts: 6
I never used arrays before, but I will try. Thanks :wink:


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic  [ 10 posts ] 

All times are UTC+02:00


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Limited