View unanswered posts | View active topics It is currently Tue Apr 21, 2026 5:38 am



Reply to topic  [ 5 posts ] 
 Input and write to file 
Author Message
Commander
User avatar

Joined: Fri Aug 20, 2004 2:00 am
Posts: 1801
Location: Outer Rims
Unread post Input and write to file
I am trying to understand the principle andconcepts of having input written to a text file for another script usage. For example, let's suppose I have to enter some sector numbers, I am stuck on how to tell the script to write each number into a text file where each sector is on its own line. Here is a snip of the code I have so far:

Code:

setvar $sectors_select "Not Set"

:Sector_Config
   echo ANSI_11 "**(1) Enter sector(s) to monitor. " ANSI_15 $sectors_select
        echo ANSI_13 "*(S) Start Script"
        echo ANSI_12 "*(Q) Abort Script"
   getConsoleInput $menuchoice singlekey
   lowercase $menuChoice

   if ($menuChoice = 1)
      setVar $sectors_select ""
      setVar $i 1
      setVar $cnt 1
      while ($i <> 0)
         echo ANSI_12 "*Enter sector number to monitor or " ansi_9 " 0 " ANSI_12 "to finish"
         echo ansi_12 "*Current sector(s) to monitor: " ANSI_15 $sectors_select "*"
         getConsoleInput $i
         add $cnt 1
         if ($i <> 0)
             setVar $sectors_select $sectors_select & $i & " "
         else
            goto :Sector_Config
         end
         end
   elseif ($menuChoice = "s") and ($sectors_select <> "Not Set")
      send "?"
      goto :final
   elseif ($menuChoice = "q")
      halt
   end
   goto :sector_Config


I based it on Promethius' gameopen script for the menu structure. I am not sure where to tell the script to write each number I enter into the file and to enter it on its own line.

The other question I have is will the "enter 0 to finish" interfere with this? Meaning if I press zero to finish it will enter the zero in the text file.

_________________
-Thrawn

But risk has always been an inescapable part of warfare.

--

Knight to Queen's Bishop 3


Sun Mar 22, 2009 9:47 pm
Profile
Ambassador
User avatar

Joined: Mon Feb 09, 2004 3:00 am
Posts: 3141
Location: Kansas
Unread post Re: Input and write to file
Thrawn wrote:
I am trying to understand the principle andconcepts of having input written to a text file for another script usage. For example, let's suppose I have to enter some sector numbers, I am stuck on how to tell the script to write each number into a text file where each sector is on its own line. Here is a snip of the code I have so far:

[pre]

setvar $sectors_select "Not Set"

:Sector_Config
echo ANSI_11 "**(1) Enter sector(s) to monitor. " ANSI_15 $sectors_select
echo ANSI_13 "*(S) Start Script"
echo ANSI_12 "*(Q) Abort Script"
getConsoleInput $menuchoice singlekey
lowercase $menuChoice

if ($menuChoice = 1)
setVar $sectors_select ""
setVar $i 1
setVar $cnt 1
while ($i <> 0)
echo ANSI_12 "*Enter sector number to monitor or " ansi_9 " 0 " ANSI_12 "to finish"
echo ansi_12 "*Current sector(s) to monitor: " ANSI_15 $sectors_select "*"
getConsoleInput $i

add $cnt 1
if ($i <> 0)
setVar $sectors_select $sectors_select & $i & " "
write $filename $i
else
goto :Sector_Config
end
end
elseif ($menuChoice = "s") and ($sectors_select <> "Not Set")
send "?"
goto :final
elseif ($menuChoice = "q")
halt
end
goto :sector_Config
[/code]

I based it on Promethius' gameopen script for the menu structure. I am not sure where to tell the script to write each number I enter into the file and to enter it on its own line.

The other question I have is will the "enter 0 to finish" interfere with this? Meaning if I press zero to finish it will enter the zero in the text file.


Since you have already tested against $i <> 0, insert the red line above to write to a file. Set $fileName to whatever your text file is supposed to be. I didn't look over the rest of the code, but that should work. One thing you could also do is test to make sure $i is a number.

_________________
               / Promethius / Enigma / Wolfen /

"A man who has no skills can be taught, a man who has no honor has nothing."


Sun Mar 22, 2009 11:39 pm
Profile ICQ
Commander
User avatar

Joined: Fri Jun 09, 2006 2:00 am
Posts: 1401
Location: Canada
Unread post Re: Input and write to file
Thrawn wrote:
I am trying to understand the principle andconcepts of having input written to a text file for another script usage. For example, let's suppose I have to enter some sector numbers, I am stuck on how to tell the script to write each number into a text file where each sector is on its own line. Here is a snip of the code I have so far:

I based it on Promethius' gameopen script for the menu structure. I am not sure where to tell the script to write each number I enter into the file and to enter it on its own line.

The other question I have is will the "enter 0 to finish" interfere with this? Meaning if I press zero to finish it will enter the zero in the text file.


I'm not sure why you want to write inputted sector data to the same line number in a text file. This will create a huge amount of over head every time you input a sector number to 'add'.

There are two ways you can approach this --assuming I'm understanding you:

1- SetArray $SOMETHING SECTORS, and flag each element in the $SOMETHING Array TRUE, as data is inputted. Then. When the user indicates that he/she is done.. cycle through the array and write your file (putting empty lines where the respective array element is FALSE)

2- Or. A more practicle approach: DELETE the file at script start up (many ways to deal with this step depending on your objective), simply append new Sector numbers to the file as they're inputted, so you get something like:

23
4311
3
4922
5834
10657
654
18534

...then the other script can read that file to a $DATA Array, and cycle through that much smaller $DATA Array while ($IDX <= $DATA) ... where $IDX were to equal 4, $DATA[$IDX] would equal '4922' ..this requires a little more work, but is far more efficient.

_________________
----------------------------
-= QUANTUM Computing 101: 15 = 3 x 5 ... 48% of the time.


Mon Mar 23, 2009 5:22 am
Profile ICQ YIM
Gameop
User avatar

Joined: Mon Jan 26, 2009 12:27 am
Posts: 123
Unread post Re: Input and write to file
I think that Thrawn what to have a file with the sector numbers and on the same line have the data to fill it up and so on other lines. So i will be able to generate a sector or many sectors with a file... Did I size you Thrawn ?

If it's your idea, I may have an idea for you. I wrote something similar but it wasn't for the same purpose.

_________________
Dodger known as Yop Solo, Sysop
twgsdodgerbbs.ath.cx
http://cyberquebec.ca/_layout/?uri=http://cyberquebec.ca/twgsdodgerbbs/


Wed Mar 25, 2009 6:41 pm
Profile
Commander
User avatar

Joined: Fri Aug 20, 2004 2:00 am
Posts: 1801
Location: Outer Rims
Unread post Re: Input and write to file
I wanted to input the sectors and have it on it's own line. However, I missed a line as Promethius pointed out and now it works perfectly ;)

The read and write was a new thing for me but now I got it understood, thanks to you all for the time and help.

_________________
-Thrawn

But risk has always been an inescapable part of warfare.

--

Knight to Queen's Bishop 3


Wed Mar 25, 2009 7:40 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 5 posts ] 

Who is online

Users browsing this forum: No registered users and 28 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.