| www.ClassicTW.com https://mail.black-squirrel.com/ |
|
| Input and write to file https://mail.black-squirrel.com/viewtopic.php?f=15&t=21710 |
Page 1 of 1 |
| Author: | Thrawn [ Sun Mar 22, 2009 9:47 pm ] |
| Post subject: | 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. |
|
| Author: | Promethius [ Sun Mar 22, 2009 11:39 pm ] |
| Post subject: | 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. |
|
| Author: | LoneStar [ Mon Mar 23, 2009 5:22 am ] |
| Post subject: | 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. |
|
| Author: | Yop_Solo [ Wed Mar 25, 2009 6:41 pm ] |
| Post subject: | 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. |
|
| Author: | Thrawn [ Wed Mar 25, 2009 7:40 pm ] |
| Post subject: | 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. |
|
| Page 1 of 1 | All times are UTC - 5 hours |
| Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |
|