| www.ClassicTW.com https://mail.black-squirrel.com/ |
|
| count lines https://mail.black-squirrel.com/viewtopic.php?f=15&t=13028 |
Page 1 of 1 |
| Author: | PHX [ Sat May 15, 2004 10:29 pm ] |
| Post subject: | |
How can a twx script count the number of lines in a txt file? I want this to grab random lines from the txt file. example file tolls.txt 1 2 3 38 734 27 etc etc etc the script commands to count number of lines in the file. $count getrnd $next 1 $count read tolls.txt $next $count I looked at this again and it don't look right...here is a quick rewrite. the script commands to count number of lines in the file. $count getrnd $rand 1 $count read tolls.txt $next $rand |
|
| Author: | Tweety [ Sun May 16, 2004 12:20 am ] |
| Post subject: | |
you have to read the file into an array. then you can pick random indexes out of that array and do with as you will. |
|
| Author: | Silence [ Sun May 16, 2004 2:03 am ] |
| Post subject: | |
Well if you just give him the code, he doesn't learn how to program the array.... granted every script has its own unique characteristics, but still. |
|
| Author: | typh00n [ Sun May 16, 2004 2:07 am ] |
| Post subject: | |
:read_txt read $fig_file $sector $count if ($sector = "EOF") goto :done_read_txt end #setVar $fig_grid[$sector] 1 add $count 1 goto :read_txt :done_read_txt #the total number of lines in this file would be represented by the $count var, or rather ($count - 1) |
|
| Author: | PHX [ Sun May 16, 2004 7:11 am ] |
| Post subject: | |
Well thanks guys ill give these a shot. Silence. Actually I do learn because I analyze every piece of code I see. I wan't to understand it, not just use it. So many of the newer -good- scripts are encrypted these days its hard to get my eyes on good code. And the examples xide gives on his "online scripting reference" are not very good at all. I have seen much better examples from existing scripts. I do still visit that page frequently though. Look at this... http://www.eisonline.com/twforum/topic. ... C_ID=17271 In the end I wound up doing the code myself. And I did learn alot. So here is another one for you guys. How can I load my VOIDS into some sort of array that I can use only 1 $var to represent all of them. Yes I will attempt it on my own as well. I imagine this would be very similar to how SSX scripts store a list of busts...with a txt file. I do have some older SSX scripts I can look at to get the idea. Heh..im at work right now and wont be able to try anything out till morning. |
|
| Author: | PHX [ Sun May 16, 2004 7:15 am ] |
| Post subject: | |
EOF seems to be a common thing...without going to look at the twx proxy code page I think I can accurately guess that means END OF FILE. I have never used it before because only today I have started working scripts that utilize txt files. |
|
| Author: | PHX [ Mon May 17, 2004 1:22 am ] |
| Post subject: | |
Very well...seing as how typhoon's version had the least code I tried it and its good. Thanks typhoon |
|
| Author: | Draconis [ Mon May 17, 2004 10:31 am ] |
| Post subject: | |
Okay, I'll throw my two cents in. Alot of it will depend on what file you are reading. Something I am starting to do with my scripts is build most of the data into memory before writing to file (depends on your application). Than you could write the first line to list the number of lines in the file. Otherwise, what Ph00n did is probably the best way. You are correct many files are encrypted today, but manys scripters are willing to help if you have questions. Feel free to contact me with questions, I'm usually very willing to help people, as well as debug code for them if I have time. Jhereg |
|
| Author: | ElderProphet [ Tue May 18, 2004 10:56 pm ] |
| Post subject: | |
I can testify first hand that Jhereg is willing to help. You know Jhereg, you've known about my haggle project longer than anyone. PHX, I added a corrected post to the forum link that you mentioned above, http://www.eisonline.com/twforum/topic. ... C_ID=17271 Somehow I missed your follow up before, or I would have posted sooner. Anyway, check that out. Here is a shorter version... just to spite Typhoon while ($toll[$line] <> EOF) add $line 1 read tolls.txt $toll[$line] $line end The total number of lines is equal to ($line - 1). Try to write the avoid capture, and post what you've got if you get stumped. +EP+ |
|
| Page 1 of 1 | All times are UTC - 5 hours |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|