Keeping data between runs
A script loses its % variables when it stops. To keep data until the next run, it has three ways, plus a
fourth for a history that people read:
*variables, saved in the Windows registry.- A settings file:
logfile writewrites a file ofsetlines, andcallruns it to set the variables again. - The
SQLcommand, which keeps data in an SQLite database file. - A log:
logfilemessages with the time in front, which you read later. A script can’t read a log back.
None of them replaces another. * variables work exactly as before, and for a few values they are still the
simplest choice. Choose by the shape of the data:
- A few named values (a counter, a setting, an ID):
*variables. - A few dozen settings that you want to see and change in Notepad, one file per character: a settings file.
- Rows of data: a list, several fields per entry, totals, or data that several scripts change at the same
time. Use
SQL. - What happened, for you to read later: a log.
At a glance
Section titled “At a glance”* variables |
Settings file | SQL |
|
|---|---|---|---|
| Where the data is | The registry, under HKCU\Software\EasyUO. |
A text file you name in logfile open. |
A file you name in sql open. |
| Setting up | Nothing: set *runs 1. |
call the file to load it. To save, logfile open … new, one logfile write per value and logfile close. |
sql open in each script, and a CREATE TABLE for your own tables. |
| Shape | One value per name. | One set line per value. A value must be one word: Dr Who comes back as Dr. |
Tables with as many rows and columns as you need. |
| Listing, searching, removing | Not from a script: you have to know the name, and no command deletes one. | Not from a script: call loads the whole file. To drop a value, stop writing it. |
SELECT … WHERE, DELETE, sql delete. |
| Totals, sorting, “in the last hour” | By hand, in a loop over numbered names. | By hand, as with * variables. |
SUM, COUNT, GROUP BY, ORDER BY, LIMIT. |
| Two scripts changing one value | A change can be lost (see below). | Each save writes the whole file, so the last script to save wins. | One statement is never interrupted by another. |
| Who sees it | Every script of your Windows user, in EasyUO Reforged and the original EasyUO. | Every script that calls the same file. | Every script that opens the same file. |
| Original EasyUO | Works there too. | logfile is new in EasyUO Reforged. The original EasyUO can still call the file. |
SQL is new in EasyUO Reforged. |
| Back up, move to another PC | reg export of the key (it holds EasyUO’s own settings too). |
Copy the file. | Copy the file. |
| Looking at the data | regedit. |
Any text editor. You can change a value by hand before the next run. | Any SQLite tool, such as DB Browser for SQLite, or Python. |
| Needs | Nothing. | Nothing. | The SQLite that ships with Windows 10 and 11 (see Using SQL). |
A file name without a folder starts from #CurPath, the folder of EasyUO Reforged,
for logfile open, call and sql open alike. So settings.txt is the same file for every script.
When * variables are enough
Section titled “When * variables are enough”- You keep a handful of values: a run counter, the ID of your loot bag, a chosen option.
- The script must also run in the original EasyUO.
- Older scripts already read or write the same
*variables.
When a settings file is the right choice
Section titled “When a settings file is the right choice”- Each character has its own settings, and you want one small file per character that you can open, read and change in Notepad.
- The script saves all its settings at once, for example when you close its menu.
- You want to copy one character’s settings to another computer, or to another character, by copying a file.
Keep in mind:
- A value must be one word.
callrunsset %name Dr Who, which sets%nametoDr. A value that starts with;comes back empty, because the line becomes a comment. IDs, numbers and words are fine. callruns every line of the file as a script. Load only files that your own scripts wrote.- Each save writes the whole file again (
logfile open … new). Two scripts saving the same file at once don’t mix their lines, but the last one to save wins. - Under
EUOCli run,logfile openonly accepts files inside the program folder, unless the run has--allow logfile.
Older scripts write these files with execute cmd /c echo … >> file. That still works, but
Save and load settings explains why logfile write is better.
When SQL is worth it
Section titled “When SQL is worth it”- The data grows over time: every kill, every pickup, every skill gain.
- An entry has several fields (an ID, a name, a place, a time) and you want to find entries by any of them.
- You want totals, averages, the five best, or only what happened in the last hour.
- Several scripts, or several clients, write the same data at once.
- You want to look at the data, back it up or clear it without opening the registry.
Keeping a history
Section titled “Keeping a history”A log is a file of messages with the date, the time, the level and the script line in front. You read it later,
in Notepad or any other tool. logfile set … daily starts a new file every day, so a
script that runs for days leaves one file per day:
logfile open loot loot.loglogfile set loot daily 30 ; a new file each day; the last 30 days are keptset %item gold ; in a real script: after each pickupset %amount 250logfile info picked up %amount %itemhaltEach message is one line, like 2026-11-18 14:03:22.123 [Info] loot.euo:5 picked up 250 gold. A script can’t
read a log back. If a script has to add up its history, keep it in SQL (see
A loot log you can add up).
Examples
Section titled “Examples”Counting runs
Section titled “Counting runs”A counter is the classic * variable, and it needs nothing else:
set *runs *runs + 1 ; N/A counts as 0, so the first run gives 1display ok This script has run *runs times.haltWith a settings file, call loads the count and logfile write saves it again:
set %runs 0call runs.txt ; sets %runs; does nothing on the first runset %runs %runs + 1logfile open runs runs.txt new ; new: write the file again from the startlogfile write runs set % , runs %runslogfile close runsdisplay ok This script has run %runs times.halt% , runs glues % to runs, so the file gets the name %runs, not its value. The file then holds one
line: set %runs 1.
The same with SQL: sql open, then sql load and
sql save around the change.
sql open mydata.dbsql load %runs ; the value saved last timeset %runs %runs + 1sql save %runs ; keep it for next timedisplay ok This script has run %runs times.haltFor a single value like this, * variables are fine.
One setting per character
Section titled “One setting per character”Several characters on one computer each need their own loot bag. With * variables, glue the character’s
ID to the name with .:
set %bag *lootbag . #CharID ; *lootbag followed by this character's IDif %bag = N/A{ set %bag ABCDEFG ; your loot bag's ID set *lootbag . #CharID %bag}display ok #CharName keeps loot in %baghaltThat works, but every character leaves a registry entry behind, and no script can list them.
With a settings file, glue the character’s ID to the file name instead. Each character gets its own small file that you can open in Notepad:
set %file lootbag , #CharID , .txtset %bag N/Acall %file ; sets %bag if this character saved oneif %bag = N/A{ set %bag ABCDEFG ; your loot bag's ID logfile open bag %file new logfile write bag #smc , Loot bag of #CharName logfile write bag set % , bag %bag logfile close bag if #LogRes <> OK display ok Not saved: #LogRes}display ok #CharName keeps loot in %baghaltThe first line of the file is a comment (#smc is ;), so you can tell the files apart.
A script still can’t list the files, though. With SQL, the characters are rows of one table, so a script
can list them all:
sql open mydata.dbsql exec CREATE TABLE IF NOT EXISTS chars(id TEXT PRIMARY KEY, name TEXT, lootbag TEXT)sql query SELECT lootbag FROM chars WHERE id = #CharIDif #SqlCnt = 0{ set %lootbag ABCDEFG ; your loot bag's ID sql exec INSERT INTO chars VALUES(#CharID, #CharName, %lootbag)}sql query SELECT name, lootbag FROM chars ORDER BY namefor %i 1 #SqlCnt{ sql row %i ; sets %name and %lootbag display ok %name keeps loot in %lootbag}haltTo forget a character, sql exec DELETE FROM chars WHERE id = #CharID removes its row.
A loot log you can add up
Section titled “A loot log you can add up”Here SQL does something no other way can. Each pickup becomes a row with the time
(#SysTime), and one query adds up the last hour:
sql open mydata.dbsql exec CREATE TABLE IF NOT EXISTS loot(at INTEGER, item TEXT, amount INTEGER)set %item gold ; in a real script: after each pickupset %amount 250sql exec INSERT INTO loot(at, item, amount) VALUES(#SysTime, %item, %amount)set %since #SysTime - 3600000 ; one hour agosql query SELECT item, SUM(amount) AS total FROM loot WHERE at > %since+ GROUP BY item ORDER BY total DESC LIMIT 5for %i 1 #SqlCnt{ sql row %i ; sets %item and %total display ok %item : %total in the last hour}haltThe same table answers other questions with one line each. For example,
SELECT COUNT(*) AS n FROM loot WHERE item = 'gold' counts the pickups of gold, and
SELECT item, MAX(amount) AS best FROM loot GROUP BY item gives the best pickup of each item.
With * variables, you would need a numbered variable for each pickup (*loot1, *loot2, …), another one
for the next number, and a loop over all of them for every total. The old entries would stay in the
registry for good. A log keeps every pickup too, but only for you to read: no script can
add it up.
Several scripts adding to one counter
Section titled “Several scripts adding to one counter”Several scripts, one per client, count kills in one shared total. With a * variable:
set *kills *kills + 1 ; reads the value, adds one, writes it backdisplay ok Kills counted by every script: *killshaltReading and writing are two separate steps. If two scripts read 41 at the same moment, both write 42
and a kill is lost. It is rare, but it happens more often as the number of scripts grows. A settings file is
no better: each script loads the file, adds one and writes the whole file again, so a kill counted by another
script in between is lost the same way.
With SQL, the database adds one in a single statement, so no other script can change the value in the
middle. A script that finds the file busy waits for its turn (up to 5 seconds):
sql open shared.dbsql exec CREATE TABLE IF NOT EXISTS counters(name TEXT PRIMARY KEY, n INTEGER)sql exec INSERT OR IGNORE INTO counters VALUES('kills', 0)sql exec UPDATE counters SET n = n + 1 WHERE name = 'kills'sql query SELECT n AS kills FROM counters WHERE name = 'kills'display ok Kills counted by every script: %killshaltEvery script has to open the same file. A name without a folder starts from #CurPath, so shared.db is
the same file for all scripts.
Moving * variables
Section titled “Moving * variables”Into a database
Section titled “Into a database”Copy each value into a % variable and save it:
sql open mydata.dbset %runs *runs ; one line for each value you want to keepset %kills *killssql save %runs %killsif #SqlRes = OK display ok Copied to mydata.dbhaltFrom then on, the script uses sql load and sql save instead of the * variables.
Into a settings file
Section titled “Into a settings file”Write one set line for each value:
logfile open cfg settings.txt newlogfile write cfg set % , runs *runs ; one line for each value you want to keeplogfile write cfg set % , kills *killslogfile close cfgif #LogRes = OK display ok Copied to settings.txthaltFrom then on, the script loads the values with call settings.txt and saves them with logfile write.
Removing the old values
Section titled “Removing the old values”The * variables stay in the registry, because no script command deletes one. To remove them, open
regedit, go to HKEY_CURRENT_USER\Software\EasyUO and delete the values whose names start with *
(set writes the names in capitals, such as *RUNS). Leave the key and its other values alone: EasyUO
keeps its own settings there.