Storing and reading data from XML files.
Forum rules
This is a sub-forum for things specific to MicroMacro.
This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
This is a sub-forum for things specific to MicroMacro.
This is not the place to ask questions about the RoM bot, which uses MicroMacro. There is a difference.
Storing and reading data from XML files.
I'm having ton of issues with this. I'm trying to make the code simple to read so my goal is to do something similar to your rom bot. I want to make a createpath.lua file to make all my paths. Some of the stuff i want to add is that it will be able to call function like yours does with harvesting and stuff.
I guess my real question is in a simple form (i tried to learn from you createpath file but there is to much). How can I setup my createpath.lua to write to a XML file and then would would i read that information. The XML will hold coords (x, y) and i need to to check if i want it to use my attack function at x,y or use my portal function at x,y.
No need to write it out for me or anything but a simple break down will work. The wiki just further confused me this time around.
I guess my real question is in a simple form (i tried to learn from you createpath file but there is to much). How can I setup my createpath.lua to write to a XML file and then would would i read that information. The XML will hold coords (x, y) and i need to to check if i want it to use my attack function at x,y or use my portal function at x,y.
No need to write it out for me or anything but a simple break down will work. The wiki just further confused me this time around.
- Administrator
- Site Admin
- Posts: 5307
- Joined: Sat Jan 05, 2008 4:21 pm
Re: Storing and reading data from XML files.
XML examples can be found on the XML module page:
http://www.solarstrike.net/wiki/index.p ... Xml_Module
To run the code from the XML files, it is read and stored as a string, and executed with the pcall function.
http://www.solarstrike.net/wiki/index.p ... Xml_Module
To run the code from the XML files, it is read and stored as a string, and executed with the pcall function.
Re: Storing and reading data from XML files.
I'm slowly learning this but I'm still not getting the info I need on reading and writing. I'm going to reread this a few times till i get it and after i have a real error i'll post it. thanks
Edit: This is my goal atm.
I need to make one single list of numbers inside my xml file to fill my table. Inside the file should look something like this..
1234, 4321, 1, 1, 3333, 2222, 2, 2
When my make my code to read this it will pair it into coords and any pair that shows up as 1, 1 will call the attack() function and anything with 2, 2 will call the teleport function. This is the most simple way i could think of to do this.
EDIT: How can i convert a table to a string?
Edit: This is my goal atm.
I need to make one single list of numbers inside my xml file to fill my table. Inside the file should look something like this..
1234, 4321, 1, 1, 3333, 2222, 2, 2
When my make my code to read this it will pair it into coords and any pair that shows up as 1, 1 will call the attack() function and anything with 2, 2 will call the teleport function. This is the most simple way i could think of to do this.
EDIT: How can i convert a table to a string?
- Administrator
- Site Admin
- Posts: 5307
- Joined: Sat Jan 05, 2008 4:21 pm
Re: Storing and reading data from XML files.
Wait, what? It should only return a string in the case of "1,1" being the value.
Second of all, you're going about this all the wrong way. The string "1,1" is going to be more difficult to work with. Instead, you should be using two separate sets of integers, like so:
This way, you can instantly get the information as needed without any extra work. If you want to use a skill through the API, this is the format you'll need the information in; not strings.
Second of all, you're going about this all the wrong way. The string "1,1" is going to be more difficult to work with. Instead, you should be using two separate sets of integers, like so:
Code: Select all
<someTag page="1" index="1" />
Re: Storing and reading data from XML files.
All i want to do is store a list of number inside the xml file.
1111, 2222, 1, 1, 2222, 3333, 2222, 3333, 2, 2
All i'd have to do from here is take that entire list of number and put it inside a table and i'm done. I don't need all the tags and stuff just the numbers. I tried to write a list to my xml file and it returned an error to me saying I pass a table where a string should be. I need to turn my table into a string to pass it to my xml file then turn the string back into a table when i read it with the bot script.
Edit: This might help if you see my code and what i plan to do.
In my save waypoint function i need to turn the argument list which will be a table into a txt format to feed to my xml file.
1111, 2222, 1, 1, 2222, 3333, 2222, 3333, 2, 2
All i'd have to do from here is take that entire list of number and put it inside a table and i'm done. I don't need all the tags and stuff just the numbers. I tried to write a list to my xml file and it returned an error to me saying I pass a table where a string should be. I need to turn my table into a string to pass it to my xml file then turn the string back into a table when i read it with the bot script.
Edit: This might help if you see my code and what i plan to do.
Code: Select all
printf("createpath.lua\n");
setStartKey(key.VK_DELETE);
setStopKey(key.VK_END);
tWp = key.VK_NUMPAD7;
tAtt = key.VK_NUMPAD8;
tPort = key.VK_NUMPAD9;
tSave = key.VK_NUMPAD6;
curX = memoryReadInt(myProc, 0x02C85944); --My current X position
curY = memoryReadInt(myProc, 0x0157D78C); --My current Y position
function saveWaypoint(list)
keyboardBufferClear();
io.stdin:flush();
printf("What do you want to name your path (without .xml)?\nName> "); -- What do you want to name your path
filename = getExecutionPath() .. "/waypoints/" .. io.stdin:read() .. ".xml";
file, err = io.open(filename, "w");
if( not file ) then
error(err, 0);
end
file:write(txtList);
end
function main()
--window = findWindow("Xenimus");
--hdc = openDC(window);
printf("\n\n\n\n\n\n\n\nXenimus Path Creation Script"
.."\n\n (7) Waypoint"
.."\n (8) Attack"
.."\n (9) Port"
.."\n (6) Save");
running = true;
while(running) do
--Checking if the key has been pressed.
local keyDown, keyType;
while(true) do
keyDown = false;
if(keyPressed(tWp)) then
keyDown = true;
keyType = "WP";
end
if(keyPressed(tAtt)) then
keyDown = true;
keyType = "ATTACK";
end
if(keyPressed(tPort)) then
keyDown = true;
keyType = "PORT"
end
if(keyPressed(tSave)) then
keyDown = true;
keyType = "SAVE";
end
local tmp = {};
--Key has been pressed and is now released.
if(keyDown == false and keyType) then
if(keyType == "SAVE") then
saveWaypoint(wpList);
keyType = "";
running = false;
break;
end
if(keyType == "WP") then
updatePlayer();
tmp = { memoryReadInt(myProc, 0x02C85944),
memoryReadInt(myProc, 0x0157D78C) }
keyType = "";
end
if(keyType == "tAtt") then
tmp = { 1, 1 };
keyType = "";
end
if(keyType == "tPort") then
tmp = { 2, 2 };
keyTpye = "";
end
end
table.insert(wpList, tmp);
end --End while true
end --End while running
end
startMacro(main);
- Administrator
- Site Admin
- Posts: 5307
- Joined: Sat Jan 05, 2008 4:21 pm
Re: Storing and reading data from XML files.
Code: Select all
local str = tab[1] .. "," .. tab[2]; -- str is now something like "1,1"
Re: Storing and reading data from XML files.
This is my code now but i'm getting an error i cannot seem to figure out.
Code: Select all
scripts\xen/createpath.lua:103: attempt to concatenate global 'wpList' (a table value)
Code: Select all
printf("createpath.lua\n");
setStartKey(key.VK_DELETE);
setStopKey(key.VK_END);
function saveWaypoint(list)
keyboardBufferClear();
io.stdin:flush();
printf("What do you want to name your path (without .xml)?\nName> "); -- What do you want to name your path
filename = getExecutionPath() .. "/waypoints/" .. io.stdin:read() .. ".xml";
file, err = io.open(filename, "w");
if( not file ) then
error(err, 0);
end
local txtList;
for i = 1, #list, 1 do
txtList = list[i] .. ",";
end
file:write(txtList);
end
function main()
tWp = key.VK_NUMPAD7;
tAtt = key.VK_NUMPAD8;
tPort = key.VK_NUMPAD9;
tSave = key.VK_NUMPAD6;
wpList = {};
myProc = openProcess( findProcess("Xenimus") );
--window = findWindow("Xenimus");
--hdc = openDC(window);
printf("\n\n\n\n\n\n\n\nXenimus Path Creation Script"
.."\n\n (7) Waypoint"
.."\n (8) Attack"
.."\n (9) Port"
.."\n (6) Save\n\n\n");
running = true;
while(running) do
--Checking if the key has been pressed.
local keyDown, keyType;
while(true) do
keyDown = false;
if(keyPressed(tWp)) then
keyDown = true;
keyType = "WP";
end
if(keyPressed(tAtt)) then
keyDown = true;
keyType = "ATTACK";
end
if(keyPressed(tPort)) then
keyDown = true;
keyType = "PORT"
end
if(keyPressed(tSave)) then
keyDown = true;
keyType = "SAVE";
end
local tmp = {}
--Key has been pressed and is now released.
if(keyDown == false and keyType) then
if(keyType == "SAVE") then
saveWaypoint(wpList);
keyType = "";
running = false;
break;
end
if(keyType == "WP") then
tmp = { memoryReadInt(myProc, 0x02C85944),
memoryReadInt(myProc, 0x0157D78C) }
printf("Waypoint: "..tmp[1]..", "..tmp[2].."\n");
keyType = "";
end
if(keyType == "tAtt") then
tmp = { 1, 1 };
if(tmp[1] == 1 and tmp[2] == 1) then
printf("Waypoint: Attack\n");
else
printf("Waypoint: Attack Failed\n");
end
keyType = "";
end
if(keyType == "tPort") then
tmp = { 2, 2 };
if(tmp[1] == 2 and tmp[2] == 2) then
printf("Waypoint: Port\n");
else
printf("Waypoint: Port Failed\n");
end
keyTpye = "";
end
table.insert(wpList, tmp);
printf("List: "..wpList.."\n");
end
end --End while true
end --End while running
end
startMacro(main);
- Administrator
- Site Admin
- Posts: 5307
- Joined: Sat Jan 05, 2008 4:21 pm
Re: Storing and reading data from XML files.
Code: Select all
printf("List: "..wpList.."\n");
Code: Select all
printf("List: "..tostring(wpList).."\n");
Re: Storing and reading data from XML files.
When i use that, I don't get an error but what i do get is confusing me even more...
This just spams constantly after i press one of my keys.
I did a few more tests and tostring() seems to just return table: (memory address). I was wanting to just print out what the table had in it so i could check it for errors.
This just spams constantly after i press one of my keys.
Code: Select all
List: table: 006C1CD0
List: table: 006C1CD0
List: table: 006C1CD0
List: table: 006C1CD0
List: table: 006C1CD0
List: table: 006C1CD0
List: table: 006C1CD0
List: table: 006C1CD0
List: table: 006C1CD0
List: table: 006C1CD0
List: table: 006C1CD0
List: table: 006C1CD0
- Administrator
- Site Admin
- Posts: 5307
- Joined: Sat Jan 05, 2008 4:21 pm
Re: Storing and reading data from XML files.
Then you would need to iterate through the table and print it out.
Code: Select all
for i,v in pairs(tab) do
printf("Tab[i]: %s\n", i, tostring(v));
end
Re: Storing and reading data from XML files.
tostring() doesn't return the right values though.
- Administrator
- Site Admin
- Posts: 5307
- Joined: Sat Jan 05, 2008 4:21 pm
Re: Storing and reading data from XML files.
That makes no sense. All tostring() does is convert it to a string.Exempt wrote:tostring() doesn't return the right values though.
Re: Storing and reading data from XML files.
It's not just converting it to a string though. It returns crazy values. Like my table was list = {53, 52, 53, 52, 53, 52}... the return was 10.
Edit: this code here is suppost to insert a value into my table right?
Say wpList was wpList = { 4, 4, 5, 5 } before using that function. After it should be wpList = { 4, 4, 5, 5, 2, 2 } right?
My goal is to fill wpList with all the waypoints I add through tmp.
Edit: this code here is suppost to insert a value into my table right?
Code: Select all
tmp = { 2, 2 };
table.insert(wpList, tmp);
My goal is to fill wpList with all the waypoints I add through tmp.
- Administrator
- Site Admin
- Posts: 5307
- Joined: Sat Jan 05, 2008 4:21 pm
Re: Storing and reading data from XML files.
You're doing it wrong then. You are going to have to provide more information if you want help.
Re: Storing and reading data from XML files.
What info do you need exactly?
Code: Select all
printf("createpath.lua\n");
setStartKey(key.VK_DELETE);
setStopKey(key.VK_END);
function saveWaypoint(list)
keyboardBufferClear();
io.stdin:flush();
printf("What do you want to name your path (without .xml)?\nName> "); -- What do you want to name your path
filename = getExecutionPath() .. "/waypoints/" .. io.stdin:read() .. ".xml";
file, err = io.open(filename, "w");
if( not file ) then
error(err, 0);
end
local txtList;
for i,v in pairs(list) do
txtList = sprintf( tostring(i)..","..tostring(v));
end
file:write(txtList);
end
function main()
tWp = key.VK_NUMPAD7;
tAtt = key.VK_NUMPAD8;
tPort = key.VK_NUMPAD9;
tSave = key.VK_NUMPAD6;
wpList = {};
myProc = openProcess( findProcess("Xenimus") );
--window = findWindow("Xenimus");
--hdc = openDC(window);
printf("\n\n\n\n\n\n\n\nXenimus Path Creation Script"
.."\n\n (7) Waypoint"
.."\n (8) Attack"
.."\n (9) Port"
.."\n (6) Save\n\n\n");
running = true;
while(running) do
--Checking if the key has been pressed.
local keyDown, keyType;
while(true) do
keyDown = false;
if(keyPressed(tWp)) then
keyDown = true;
keyType = "WP";
end
if(keyPressed(tAtt)) then
keyDown = true;
keyType = "ATTACK";
end
if(keyPressed(tPort)) then
keyDown = true;
keyType = "PORT"
end
if(keyPressed(tSave)) then
keyDown = true;
keyType = "SAVE";
end
local tmp = {}
--Key has been pressed and is now released.
if(keyDown == false and keyType) then
if(keyType == "SAVE") then
saveWaypoint(wpList);
keyType = "";
running = false;
break;
elseif(keyType == "WP") then
tmp = { memoryReadInt(myProc, 0x02C85944),
memoryReadInt(myProc, 0x0157D78C) }
table.insert(wpList, tmp);
printf("Waypoint: "..tmp[1]..", "..tmp[2].."\n");
keyType = "";
for i,v in pairs(list) do
print("Coords: "..tostring(i)..","..tostring(v).."\n";
end
elseif(keyType == "ATTACK") then
tmp = { 1, 1 };
table.insert(wpList, tmp);
if(tmp[1] == 1 and tmp[2] == 1) then
printf("Waypoint: Attack\n");
else
printf("Waypoint: Attack Failed\n");
end
keyType = "";
elseif(keyType == "PORT") then
tmp = { 2, 2 };
table.insert(wpList, tmp);
if(tmp[1] == 2 and tmp[2] == 2) then
printf("Waypoint: Port\n");
else
printf("Waypoint: Port Failed\n");
end
keyType = "";
end
end
end --End while true
end --End while running
end
startMacro(main);
- Administrator
- Site Admin
- Posts: 5307
- Joined: Sat Jan 05, 2008 4:21 pm
Re: Storing and reading data from XML files.
Code: Select all
Say wpList was wpList = { 4, 4, 5, 5 } before using that function. After it should be wpList = { 4, 4, 5, 5, 2, 2 } right?
Code: Select all
local tmp = {1, 2};
table.insert(list, tmp);
for i = 1,#list do
local t = list[i];
local x, y = t[1], t[2];
-- just in case there was an error
x = x or -1;
y = y or -1;
printf("x: %d, y: %d\n", x, y);
end
Re: Storing and reading data from XML files.
Hm, I don't know why i can't grasp this. All i want to do it make a simple script to write one single list to a xml file. I'm going to try what you said there and see what i can get going. thanks again
Who is online
Users browsing this forum: No registered users and 0 guests