You must be logged in to post messages.
Please login or register

AI & RM Scripting
Moderated by Leif Ericson

Hop to:    
Welcome! You are not logged in. Please Login or Register.1 reply
Age of Kings Heaven » Forums » AI & RM Scripting » Slimmer RMS: ES@The_Unknown_v2 loses 31 KB!
Bottom
Topic Subject:Slimmer RMS: ES@The_Unknown_v2 loses 31 KB!
local boi
Squire
(id: dragon14)
posted 07-15-18 06:48 AM CT (US)         
NOTE: The online ide in Step One crashes with big maps. Use an ide and i/o with big maps (I use zerobrane) (see second post for details)

What it does:

* remove normal /* ** */ comments (but not any others; anything that's undefined seems to work as a comment)
* less whitespace (newlines, tabs and extra spaces become a single space)
* you can see big improvement in file size for a lot of maps, just because it puts everything on one line

Known Issues:


How to use:

Step One: Go to this website https://www.jdoodle.com/execute-lua-online

Step Two: Delete the stock lua code
local x = 10
local y = 25
local z = x + y

print("Sum of x+y =",z)
and replace it with this code

local MAP = [[]]

function make_table(STRING)
local pattern,captures,i, ignore,keep = "%g+",{},1, 0,{}
for c in string.gmatch(STRING, pattern) do
captures[i],i = c,i+1
end
for i,v in ipairs(captures) do
if v == "/*" then
ignore=ignore+1
end
if ignore == 0 then
table.insert(keep, v)
end
if v == "*/" then
ignore=ignore-1
end
end
return table.concat(keep," ")
end
print(make_table(MAP))





Step Three: Open your Random Map Script and copy it

Step Four: Paste your Random Map Script INBETWEEN THE [[...]]

It should look a little something like this

local MAP =
[[ ... DO STUFF ...]]

Step Five:

Run it. It should take a few seconds at most.

Step Six: Copy the output to an empty text file

Step Seven: Save your file.

Step Eight: Test your map to make sure this trick works

Did this need its own post: no.

USA
katsup or mustard

[This message has been edited by local boi (edited 07-15-2018 @ 08:11 AM).]

AuthorReplies:
local boi
Squire
(id: dragon14)
posted 07-15-18 07:52 AM CT (US)     1 / 1       
If you have zerobrane or whatever this way is a lot faster

For some extreme example, it stripped RageQuit Random V9 from ~2000 KB to ~1500 KB. Which is still a ridiculous amount.

local m1 = {}
local i = 1
for line in io.lines("File.txt") do
m1[i] = line
i = i+1
end

function clean(STRING)
local pattern,captures,i, ignore,keep = "%g+",{},1, 0,{}
for c in string.gmatch(STRING, pattern) do
captures[i],i = c,i+1
end
for i,v in ipairs(captures) do
if v == "/*" then
ignore=ignore+1
end
if ignore == 0 then
table.insert(keep, v)
end
if v == "*/" then
ignore=ignore-1
end
end
return table.concat(keep," ")
end

local str = table.concat(m1," ")
str = clean(str)
file1 = io.open("File.txt", "w")
file1:write(str)
file1:close()

USA
katsup or mustard

[This message has been edited by local boi (edited 07-15-2018 @ 08:05 AM).]

You must be logged in to post messages.
Please login or register

Hop to:    

Age of Kings Heaven | HeavenGames