Another question

Ask for help

Moderators: Murderator+, Murderator

Post Reply
Gautman
Posts: 6
Joined: 2005-05-07 01:34:07

Another question

Post by Gautman »

I am working on this script to macro my carpentry skill. The script works but there remain a little problem :

Code: Select all

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: Select all

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
Beyonder
Expert!
Posts: 388
Joined: 2005-04-23 10:19:43
Contact:

Post by Beyonder »

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.
Gautman
Posts: 6
Joined: 2005-05-07 01:34:07

Post by Gautman »

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...
Beyonder
Expert!
Posts: 388
Joined: 2005-04-23 10:19:43
Contact:

Post by Beyonder »

Problem is that you should use abslute path to the file. Like "C:\Test.txt".
Gautman
Posts: 6
Joined: 2005-05-07 01:34:07

Post by Gautman »

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.
Beyonder
Expert!
Posts: 388
Joined: 2005-04-23 10:19:43
Contact:

Post by Beyonder »

Try this way:

Code: Select all

var f
<loop start>
f=file('filename')
f.Open()
......
f.Close()
<loop end>


I mean to put f=file('filename') definition into the loop.
Beyonder
Expert!
Posts: 388
Joined: 2005-04-23 10:19:43
Contact:

Post by Beyonder »

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.
Gautman
Posts: 6
Joined: 2005-05-07 01:34:07

Post by Gautman »

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 !
Beyonder
Expert!
Posts: 388
Joined: 2005-04-23 10:19:43
Contact:

Post by Beyonder »

I didnt mean about the looping, i meant about the reading from file.
Cant you do it like this:

Code: Select all

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.
Gautman
Posts: 6
Joined: 2005-05-07 01:34:07

Post by Gautman »

I never used arrays before, but I will try. Thanks :wink:
Post Reply