ScriptUO

Official ScriptUO EasyUO Scripts => Scripting Chat => Topic started by: Paulonius on November 19, 2012, 04:35:10 PM

Title: Looking for a tutorial on creating data files
Post by: Paulonius on November 19, 2012, 04:35:10 PM
I am interested in learning how to create retrievable data files for things like: setting a series of waypoints, creating a list of people who are mean to me, saving a bunch of tarket clicks -- you get the idea. If someone really smart like (TM, Cerv, EN, Crome...) has 20 minutes to write up a basic, comprehensive tutorial on creating a sub that will write a retriveable file and (also important) a sub for retrieving the data, that would be super cool.
Title: Re: Looking for a tutorial on creating data files
Post by: Cerveza on November 19, 2012, 05:29:33 PM
That's pretty insulting to TM, EN and Crome.
Title: Re: Looking for a tutorial on creating data files
Post by: Endless Night on November 19, 2012, 05:35:33 PM
2 methods

(1) Registry values
      set *this that

(2) File
Load Method
  call Myfile.txt

Save Method - write out the data in code
  ie set %this that

  exectution
  gosub ENs_SetupCommandLine
  set %PercentSign %
  set %Output  set , #spc , %PercentSign , This , #spc , That
  Execute %Cmd /c Echo %output >> Myfile.txt

Code: [Select]
Sub ENs_SetupCommandLine
  Set %Cmd cmd.exe
  Str Left #OSVer 1
  If #StrRes = 1
      Set %Cmd command.com
  If #StrRes = 2
      Set %Cmd cmd.exe
Return
Title: Re: Looking for a tutorial on creating data files
Post by: Endless Night on November 19, 2012, 06:16:09 PM
I'll one up myself and heres all the code you need :->> http://www.scriptuo.com/index.php?topic=2454.msg88662#msg88662

Can load save multiple vars in a single line.... very nice.. had been meaning to finish that forever.,.  ... enjoy
Title: Re: Looking for a tutorial on creating data files
Post by: manwinc on November 19, 2012, 07:09:14 PM
Pretty much everything en said. You also might look into road kills writefastarray  sub or... Something or another... Its very handy at saving large quantities of data into text files at once
Title: Re: Looking for a tutorial on creating data files
Post by: Paulonius on November 19, 2012, 07:13:23 PM
I knew you had something handy EN, thanks a ton!! I have been looking at subs trying to figure it out, but wanted something clean to learn from.
Title: Re: Looking for a tutorial on creating data files
Post by: Endless Night on November 19, 2012, 07:16:13 PM
I knew you had something handy EN, thanks a ton!! I have been looking at subs trying to figure it out, but wanted something clean to learn from.

I editted the post .. follow the link.. allows you to save multi vars in one shot.
Title: Re: Looking for a tutorial on creating data files
Post by: manwinc on November 19, 2012, 07:33:59 PM
OOo... Nice. I shall have to give that one a try myself.
Title: Re: Looking for a tutorial on creating data files
Post by: Endless Night on November 19, 2012, 07:37:28 PM
OOo... Nice. I shall have to give that one a try myself.



Yea pretty usefull bit of code for sure.
Title: Re: Looking for a tutorial on creating data files
Post by: Paulonius on November 20, 2012, 03:35:28 AM
Your tool kit got me thinking, so figured I would ask!
Title: Re: Looking for a tutorial on creating data files
Post by: Paulonius on November 20, 2012, 02:20:41 PM
I am liking this. Digging in and I have a few questions.

Is there a limit on the number of parameters I can send with this system?

I have not looked at parsing the percentage sign from the front of a variable before, but that seems like something that would be good to be able to do so that the save data sub could accept dynamic variables. Is that even possible?

Code: [Select]
gosub ENs_SaveData %File_Path_And_Name_txt TestVar TestVar2

I took your test code and played about a bit pulling the file path off of the file name and I got that working so that I can have a dynamic file name for use in building sets of data.  

Code: [Select]
Event Macro 1 0 STARTING TEST
wAIT 5
SET %TestVar 1
set %testvar2 test
set %File_Name Data_test
Set %File_Path C:\Users\CRS\Desktop\EUO\
set %File_Name_txt Data_test . .txt
;Event exmsg #charid 3 4 TEST MESSAGE The file is now named %File_Name_txt
Set %File_Path_And_Name_txt %File_Path , %File_Name_txt
;Event exmsg #charid 3 4 TEST MESSAGE  The File path with the file name %File_Path_And_Name_txt is saveing a test value of %testvar - %testvar2
goSub ENs_ClearFile %File_Path_And_Name_txt
gosub ENs_SaveData %File_Path_And_Name_txt TestVar TestVar2
; ~~~~~~~~~~~~~~~~~~~
set %testvar 2
set %testvar2 boo
;Event exmsg #charid 3 4 TEST MESSAGE  reseting testvalue to %testvar : %testvar2
; ~~~~~~~~~~~~~~~~~~~
gosub ENs_LoadData %File_Path_And_Name_txt
;Event exmsg #charid 3 4 TEST MESSAGE TestValue = %testvar : %testvar2 $ (should be 1 : test what was saved in file)
halt
Title: Re: Looking for a tutorial on creating data files
Post by: Endless Night on November 20, 2012, 06:15:53 PM
Thier is a limit for each time you call the gosub.. that is a total string lenght (buffertext) of 1700 characters.  String length =  (Number of vars * (18 +  Lenght of filename/path ) ) + Lenght Of each VarNAme sent + Lenght of each of the actual vars

Thier is No limit to the number of vars you can send that fit inside the above criteria. Of course if you think you are getting close just split it over a number of gosub ENs_SaveData Lines .. Each call to SaveData APPENDS to the file .. thats why in my example code i clear the file first.

I could implement a detection of the 1700 char limit, in other IO code i have done this... so if you think you might hit the limit I will add it

Title: Re: Looking for a tutorial on creating data files
Post by: Paulonius on November 21, 2012, 06:42:07 AM
I did a little more testing with this code and confirmed that you can use a variable in the gosub ENs_SaveData call line.

The tool becomes really flexible once you start using string and apend as it will allow you to pair a sequenced variable with a sequenced variable name (See below). If you run a character counter you can use that as a trigger to use the same process to promote the file name -- so yes, I think we do want a counter sub also.

I broke apart the file path from the file name so that the name could easily be promoted with a trigger from a character count sub.  While is not used in this example, I wanted to show that I had it working to demonstrate that automatically promoting the file name is possible.

My test script looked like this:

Code: [Select]
Set %Test_Variable Blah
Set %Test_Variable_Save Test_Variable
Set %File_Name Data_test
Set %File_Path C:\Users\CRS\Desktop\EUO\
Set %File_Name_txt Data_test . .txt
Set %File_Path_And_Name_txt %File_Path , %File_Name_txt
goSub ENs_ClearFile %File_Path_And_Name_txt
For %X 1 10
    {
    Set %Test_Variable_Save . %X %Test_Variable_Save , %X
    Set %Test_Variable . %X %Test_Variable , %X
    gosub ENs_SaveData %File_Path_And_Name_txt %Test_Variable_Save . %X
    }
Halt

The data file it created, appeared in my UO file named Data_test.txt  and it looks like this:

Code: [Select]
Set %Test_Variable1 Blah1
Set %Test_Variable2 Blah2
Set %Test_Variable3 Blah3
Set %Test_Variable4 Blah4
Set %Test_Variable5 Blah5
Set %Test_Variable6 Blah6
Set %Test_Variable7 Blah7
Set %Test_Variable8 Blah8
Set %Test_Variable9 Blah9
Set %Test_Variable10 Blah10

Pretty much exactly what I was looking for EN!!


 
Title: Re: Looking for a tutorial on creating data files
Post by: Endless Night on November 21, 2012, 08:54:34 AM
Nice Paulonius... using a var to reference a var  sweet gooble gooble   


Saving script config setups just got a whole lot easier didnt it.
Title: Re: Looking for a tutorial on creating data files
Post by: Paulonius on November 21, 2012, 09:48:25 AM
A lot of cool stuff we can do with this. 

Could you share what you did to calculate character count?
Title: Re: Looking for a tutorial on creating data files
Post by: Endless Night on November 21, 2012, 03:16:23 PM
A lot of cool stuff we can do with this. 

Could you share what you did to calculate character count?

From my character toolbox script

Code: [Select]
; ---------------------------------------
; log subs
;----------------------------------------

sub DumpOutputToFile
 set %oldlpc #lpc
 set #lpc 5000
 set !AutoOpenNotePad %1
 set !ResultFile %2

 If %OutputLines <> N/A && %OutputLines > 99
   {
   goSub FileIoStringFormat %Output100
   Set !BufferText Echo , #spc , #Result , #spc , > , #SPC , !Resultfile
   If %OutputLines > 100
     {
     For !x 101 %OutputLines
       {
       goSub FileIoStringFormat %Output . !x
       str Len !BufferText
       If #StrRes > 0
         Set !BufferText !BufferText , #spc , && , #spc , Echo , #spc , #result , #spc , >> , #spc , !Resultfile
       ELSE
         Set !BufferText Echo , #spc , #Result , #spc , >> , #spc , !Resultfile

       IF #strres > 1700
         {
;         display ok !BufferText
         Execute cmd.exe /c !BufferText
         set !BufferText
         wait 5
         }
       }
     }
   str Len !BufferText
   If #strres > 0
     Execute cmd.exe /c !BufferText
   }

 IF !AutoOpenNotePad = #True
    Execute Notepad !ResultFile

 Set #lpc %oldLpc
Return

Sub FileIoStringFormat
  Str Len %1
  set !NewString
  For !xxcount 1 #Strres
    {
     Str Mid %1 !xxcount 1
     If #StrRes In &|();.%
       Set !NewString !NewString , ^ , #strres
     Else
       Set !NewString !NewString , #strres
    }
Return !NewString

sub RecordOutput
  If %0 > 0 && %0 <> N/A
    {
    If %OutputLines = N/A
       Set %OutputLines 99
    Set %OutputLines %OutputLines + 1
    Set %Output . %OutputLines
    For !Count 1 %0
      Set %Output . %OutputLines %Output . %OutputLines , #spc , % . !Count
    }
return
Title: Re: Looking for a tutorial on creating data files
Post by: Paulonius on November 26, 2012, 04:57:28 AM
Using EN's data file tool I wrote a simple hotkey script to write a rail data file as follows:

Code: [Select]
Set %Rail_Name SPR1
Set %File_Name %Rail_Name
Set %File_Name_txt %File_Name , .txt
Set %File_Path C:\Users\CRS\Desktop\EUO\
Set %File_Path_And_Name_txt %File_Path , %File_Name_txt
Set %WP_Save WP
GoSub ENs_ClearFile %File_Path_And_Name_txt
Set %X 0
Repeat
      {
      onhotkey f4
      Set %HotKey4 True
      onhotkey f5
      Set %HotKey5 True
      If %HotKey4 = True
         {
         Set %X %X + 1
         Set %WP_Save . %X %WP_Save , %X
         Set %WP . %X X . #CHARPOSX , Y . #CHARPOSY , Z . #CHARPOSZ
         Event exmsg #charid 3 4 %WP . %X
         gosub ENs_SaveData %File_Path_And_Name_txt %WP_Save . %X
         Set %HotKey4 False
         }
      }
Until %HotKey5 = True
Set %WP_Count %X
Gosub ENs_SaveData %File_Path_And_Name_txt WP_Count
Halt


I ran the code, hit F4 four times and then hit F5. The rail file is named SPR1 and looks like this:

Code: [Select]
; ENs Var Save
Set %WP1 X2164Y2169Z7
Set %WP2 X2164Y2169Z7
Set %WP3 X2164Y2169Z7
Set %WP4 X2164Y2169Z7
Set %WP_Count 4

Next I will add in the character count code.
Title: Re: Looking for a tutorial on creating data files
Post by: Endless Night on November 26, 2012, 08:11:22 AM
nice Paulonius  ..
Title: Re: Looking for a tutorial on creating data files
Post by: Paulonius on November 27, 2012, 06:56:51 AM
I modified the waypoint recording script to use hashmarks to break up the data points so that I could use TM's string parser to break them up when I pull them into a script.

Then I added a step by step pathfind through the waypoints by modifying the waypoint script, and used that to create a second script that will make files for hatchet/shovel strikes along the waypoint, using a similar naming convention.

I now have a set of scripts that I can use to make rails for mining or lumberjacking. It takes about five minutes to record a decent rail, and another 5-10 to add the shovel/hatchet data points.
Title: Re: Looking for a tutorial on creating data files
Post by: Endless Night on November 27, 2012, 08:48:30 AM
sweet... That sounds like some nice work .. custom rails for the win

Have you ever checked out my super compressed rail system thats in the character tool box...   The rail to move from newchar spot in new haven to the new haven inn is 34k2z1f1h7d193ZNCf1  and to move from the new haven inn to new haven moongate is 30d593ZNCk5h4s5f6e75l6n7z5a5d6z5o5c7w5t7a5  from luna moongate to luna inn is 36g1g7f5a7f1p7a593BQCf5a3

A complex rail in one Var.  ;)   Only action it currently supports is opening doors thow.. but your work makes me want to add more actions .. but too many projects right now as it is.  
Title: Re: Looking for a tutorial on creating data files
Post by: Paulonius on November 27, 2012, 09:09:34 AM
I will take a look!!