Page 1 of 1
REQ: $read and /write and $find functions...
Posted: Sat Jul 05, 2003 12:04 am
by YKW-28983
$read
Code: Select all
$read filename line
$read CoolStuff.Txt 5
Would read line 5 of CoolStuff.txt
----------------------------------------------------------------
/write
Code: Select all
/write filename option text line
/write CoolStuff.Txt a Hello There 5
would write Hello There on line 5 of CoolStuff.txt
/write CoolStuff.Txt c Hello There
would clear CoolStuff.Txt and write Hello There on the first line. Also have the option to clear the text file completely.
----------------------------------------------------------------
$find
Code: Select all
$find filename option text
$find BobsSpells.txt e Spirit Of Wolf
Searches bobsspells.txt for Spirit Of Wolf and gives back the line #
(matching is exact but not case sensative)
$find BobsSpells.txt w Spirit Of
Searchs bobsspells.txt for *Spirit of* and returns the lines it is on
(matching is a wild card)
Script Example
Code: Select all
#event CAST "you begin to cast"
sub main
:loop
/doevents
/goto :loop
/return
sub event_cast
/varset v1 $find bobsspells.txt e $arg(5, "$p0") | or whatever it is to get the spell name
/varset v2 $read bobsspells.txt $v1
/varset t1 $arg(2, "$v2")
sub event_timer
|unsure on the timer event stuff but...
if $p0 == t1 { /cast spell $v2 }
That's just ruff code. im a little rusty from being inactive for a while.
Posted: Sat Jul 05, 2003 12:15 am
by kagonis
Very nice. A few quick questions..
/write CoolStuff.Txt a Hello There 5
What happens to what is allready on line 5?
Does it:
a) Moved down 1 line?
b) Overwritten?
Perhaps make a few more options to the /write to give the user more control?
/write <filename> <option> <string> [line]
Options:
a: append
- Will append to the file, inserting the line after the line specified. Omitting the line number will insert the line to the end of the file.
p: prepend
- Will prepend to the file, inserting the line before the line specified. Omitting the line number will insert the line as the very first line in the file, moving all other lines 1 line down.
o: overwrite
- Will overwrite the line specified, with the string submitted. A line number -must- be specified with this option.
c: clear
- Will clear the file, and if a string is submitted to, that string will be added on the first line of the cleared file.
---
$read CoolStuff.Txt 5
What happens if the file have less than 5 lines?
Does it:
a) Return some kind of EOF (End Of File) value?
b) Act like it is just an empty line and go on?
c) Crash the eqclient or something? ;)
I really hope for option "a" here, since then a simple macro like the following could be used to read an entire file line by line:
Code: Select all
Sub Main
/varset l0 1
:Loop
/varset l1 $reat myfile.txt $l0
/if "$eof"!="true" {
/echo $l1
/varadd l0 1
} else /goto :End
/goto :Loop
:End
/return
Keep up the good work :)
Posted: Sat Jul 05, 2003 12:53 am
by YKW-28983
kagonis wrote:
$read CoolStuff.Txt 5
What happens if the file have less than 5 lines?
Just leaves it blank or can return $null.
also think you misunderstood the post. am requesting these functions ...

Posted: Sat Jul 05, 2003 4:31 am
by Valerian
we already have INI functionality in CVS, why will that not work for you?
http://macroquest2.com/phpBB2/viewtopic.php?t=2596
Posted: Sat Jul 05, 2003 8:07 am
by Jalapeno
I love a chance to show off the INI functionality in use.
Here is an example of doing what you mentioned in your request using INI file access. There isn't much to it but I wanted to show that it could be done fairly simply with INI.
Here is the code:
Code: Select all
|**
[7-6-2003]
Thanks to Valerian for catching something I overlooked.
Added the pipe | before list being returned and around
the spell being cast. So that healing would not be
confused with complete healing or what have ya.
[7-5-2003]
Jalapeno
Another example of how to use ini.
A simple spell "Repeator"
It keeps casting the spell over and over
based on a specified duration set in an ini
file.
Of course you can edit this to watch multiple
spells. Among many other things.
=) enjoy
**|
#turbo 25
#event CAST "You begin casting"
Sub Main
| Set $v0 to the path of the ini file.
/varset v0 "C:\castingdata.ini"
:Loop
/doevents
/goto :Loop
/return
Sub Event_CAST
| Return all the section names.
| In this case these are the names
| of the spells.
/varset v1 "|$ini("$v0")"
| Grab the name of the spell
| being cast.
/varset v2 "|$mid(18,$calc($strlen("$p0")-19),"$p0")|"
| Compare the name of the spell being
| cast to the spell list.
/if "$v1"~~"$v2" {
| If it is found set up a timer based
| on the duration specified in the ini.
/varset v3 $ini("$v0","$v2","Duration")
/varset t0 $v3
} else {
| Tell you that you need to document this
| spell in your ini.
/echo You do not have that spell documented.
}
/return
Sub Event_Timer
/if $p0==0 {
| When the timer goes off cast the
| corresponding spell.
/cast "$v2"
}
| If you want to keep refreshing
| the spell then add this line.
/varset t$p0 $p1
/return
And here is an example of how the INI file should look:
Code: Select all
castingdata.ini
[superior healing]
duration=10s
[resolution]
duration=20m
[bulwark of faith]
duration=20m
the durations are no where near right I just threw that in there as an example.
You could have a field day with this...
Anyway there ya go, hope that helps some.
Posted: Sat Jul 05, 2003 3:52 pm
by Valerian
You suck. You're still using the OLD format for getting lists! the -1 parms aren't required anymore, just leave them out completely...
becomes
oh, and this wouldn't work anyway... try this instead:
Code: Select all
/varset v1 "[b]|[/b]$ini("$v0")"
[b] NOTE ABOVE: Insert | before the list... see why below.[/b]
| Grab the name of the spell
| being cast.
[b]| NOTE: Add the | before & after the spell name, otherwise[/b]
[b]| "Healing" will match "Greater Healing", "Superior Healing" etc.[/b]
/varset v2 "|$mid(18,$calc($strlen("$p0")-19),"$p0")[b]|[/b]"
| Compare the name of the spell being
| cast to the spell list.
/if "$v1"~~"$v2" {
Posted: Sat Jul 05, 2003 10:10 pm
by Jalapeno
You suck.
Lol, ok. Your right. I threw that together in minutes without even testing it... Overlooked the pipe sign for singling out the exact spell name. Anyway, forgot about the not having to send params no biggie.
Thanks for the correction and substitute implementation of a command.
- Jala
Posted: Sun Jul 06, 2003 4:25 am
by Valerian
I suck? haha. sucking makes good programming, apparently... I like to think of what could go wrong when I write something, and fix it before it happens

Posted: Sun Jul 06, 2003 5:50 pm
by kagonis
I do agree that the ini functionality covers a lot of stuff, but it can't really be used to read any other plaintext file that isn't structured as an ini file.
Is the ini stuff in CVS by the way, or is it still just as a "cut this code from this post and edit the file yourself before compile"? :)
Posted: Sun Jul 06, 2003 6:00 pm
by Valerian
it's in CVS
Posted: Sun Jul 06, 2003 6:04 pm
by BlueSkies
It's in the CVS.
After consideration, Jala and I have decided that file I/O other than the INI we've already implemented would really not serve any real purpose, outside of what INI I/O already supplies.
If you can think of a reason to implement it, something that can't be covered by INI functionality, let us know and we'll look into it. :)
File IO
Posted: Mon Jul 07, 2003 12:40 pm
by Spanky_Monkey
Personally I think it would be a great way to have many many pull messages for a warrior type. For example, a file with 30 different pull messages... make a macro to randomly select fa line to send to the group... could also add them, and a facility for counting the lines would be cool too. Just a thought, but man I love this program

Posted: Mon Jul 07, 2003 1:45 pm
by kagonis
BlueSkies wrote:If you can think of a reason to implement it, something that can't be covered by INI functionality, let us know and we'll look into it. :)
I allready did that.
Kagonis wrote:I do agree that the ini functionality covers a lot of stuff, but it can't really be used to read any other plaintext file that isn't structured as an ini file.
If I want to read some lines from a file that is NOT structured as an ini file.
Examples could be to read snippets from a log, from a webpage, you name it.
If first I can read a line from any plaintext file, then I could probably split that line down and use the info. Perhaps XML files?
The write function could be used as is, if you don't mind the ini structure of hos everything must be written
[section]
key=value
Allthough creating a seperate logfile for each macro, or log certain things from each macro would certainly be oddlooking if structured as an ini file.