View unanswered posts | View active topics It is currently Sat Apr 18, 2026 9:05 pm



Reply to topic  [ 9 posts ] 
 count lines 
Author Message
Lieutenant

Joined: Sat Mar 03, 2001 3:00 am
Posts: 592
Location: USA
Unread post 
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


Sat May 15, 2004 10:29 pm
Profile ICQ YIM WWW
Boo! inc.

Joined: Fri Jan 04, 2002 3:00 am
Posts: 221
Location: Canada
Unread post 
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.


Sun May 16, 2004 12:20 am
Profile
Commander

Joined: Tue Mar 26, 2002 3:00 am
Posts: 1416
Location: Canada
Unread post 
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.


Sun May 16, 2004 2:03 am
Profile ICQ
Chief Warrant Officer
User avatar

Joined: Sun Mar 30, 2003 3:00 am
Posts: 186
Location: USA
Unread post 
: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)


Sun May 16, 2004 2:07 am
Profile
Lieutenant

Joined: Sat Mar 03, 2001 3:00 am
Posts: 592
Location: USA
Unread post 
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.


Sun May 16, 2004 7:11 am
Profile ICQ YIM WWW
Lieutenant

Joined: Sat Mar 03, 2001 3:00 am
Posts: 592
Location: USA
Unread post 
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.


Sun May 16, 2004 7:15 am
Profile ICQ YIM WWW
Lieutenant

Joined: Sat Mar 03, 2001 3:00 am
Posts: 592
Location: USA
Unread post 
Very well...seing as how typhoon's version had the least code I tried it and its good.

Thanks typhoon


Mon May 17, 2004 1:22 am
Profile ICQ YIM WWW
Lieutenant J.G.

Joined: Wed Oct 15, 2003 2:00 am
Posts: 437
Location: USA
Unread post 
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


Mon May 17, 2004 10:31 am
Profile ICQ YIM
Commander
User avatar

Joined: Tue Oct 07, 2003 2:00 am
Posts: 1134
Location: Augusta, GA
Unread post 
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+

_________________
Claim to Fame: only guy to ever crack the TW haggle algorithm, and fig/shield/hold price formula, twice.


Tue May 18, 2004 10:56 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 9 posts ] 

Who is online

Users browsing this forum: No registered users and 18 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by wSTSoftware.