1

I'm new to do this language and i'm trying to code my own bot. I alredy got the basics and manage to use variables and aliases, however i was looking forward to do a mini-game in my chat in which you could have your own pet, name it and level it up.

I could do all this, however my problem resides in that at the end of the day, i would close the program and all the pets would go away, and that kind of destroys the purpose of it.

I was wondering if there was any way in i could save these variables and reload them each time i open the program, maybe save them on a .txt?

Any suggestion are greatly appreciated.

  • Just using the `/set` command works: `/set %var value`. This will save your variables even when you closed mIRC. –  Jul 17 '15 at 23:13

1 Answers1

1

I agree with one of the comments that it's best to go with .ini files for this problem.

An example of the syntax, taken from the url linked above:

writeini reminder.ini birthday jenna 2/28/1983
writeini reminder.ini birthday Mike 10/10/1990

This produces the following file:

[birthday]
jenna  = 2/28/1983
Mike   = 10/10/1990

And is to be read like this:

echo -a Mike: $readini(reminder.ini, n, birthday, mike)
echo -a Jenna: $readini(reminder.ini, n, birthday, jenna)

If you want more flexibility to define your own data format, you can also revert to plain text files. The basic /write and $read functions have some pretty neat functionality: see the docs

Something like this should work for writing:

; search if the pet is already saved
$read(pets.txt,ns,%petname)
if ($readn == 0) {
    ; append to end of file
    write pets.txt %petname %age %mood
}
else {
    ; replace line
    write -l $readn pets.txt %petname %age %mood
}

To retrieve specific pets:

var %pet_info = $read(pets.txt, ns, %petname)
; Split the found line on space (ASCII-code 32)
tokenize 32 %pet_info
var %age = $2
var %mood = $3

This returns the line that starts with the petname you're looking for.

wvdz
  • 16,251
  • 4
  • 53
  • 90
  • Yeah i was thinking on creating variables such as $+(%petname.,$nick) and put them like that on a txt. What does the nr stands for? how does the code diferentiates the name from the age? – Juan F. Caracciolo Jul 16 '15 at 20:51
  • Just make your own standard for what the file must look like. Here I use spaces as delimiters, which would break if the variables contain spaces themselves. – wvdz Jul 16 '15 at 20:58
  • @JuanF.Caracciolo better to use `ns` actually, that only matches the start of the line – wvdz Jul 16 '15 at 21:09
  • I think it better to use ini files here. @JuanF.Caracciolo the `n switch` is used to treat lines as plain text. `r switch` is for regex match, which was not used. –  Jul 17 '15 at 23:23