Few Lua Questions

Discuss, ask for help, share ideas, give suggestions, read tutorials, and tell us about bugs you have found with MicroMacro in here.

Do not post RoM-Bot stuff here. There is a subforum for that.
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.
Post Reply
Message
Author
Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Few Lua Questions

#1 Post by Exempt » Wed Jan 27, 2010 11:40 pm

I hate to ask here but i keep looking for a tutorials for this and i can't seem to get it working right.

My goal is to make me walk function take two tables as it's arguments then go through each element in the tables using them as coords to move.

I tried to just use a if statement to change mtX i = i+1... But i get an error saying lua30: attempt to perform arithmetic on local 'mtX' (a table value)
Sadly I removed that code. All i really need to know is how to pass and change a value of a table into my function.

Code: Select all

printf("fff\n");


function main()
	myProc = openProcess( findProcess("fff") );
	--attach( findWindow( fff" ));
	printf( "Xenimus Hwnd: %s \n", myProc );
	
	mouseX = 0x027C5B6C; --Mouse X position memory address
	mouseY = 0x02484014; --Mouse Y position memory address
	i = 0;
	
	desX = {2730, 2729, 2721, 2710, 2707, 2712, 2714, 2727, 2730}; --These 2 will be my destination x, y... where i want to walk to.
	desY = {2758, 2768, 2772, 2768, 2773, 2776, 2770, 2772, 2764};
	
	setStartKey(key.VK_DELETE);
	setStopKey(key.VK_END);
	
	function moveTo(mtX, mtY)
		curX = memoryReadInt(myProc, 0x02C84944); --My current X position
		curY = memoryReadInt(myProc, 0x0157C78C); --My current Y position
	
		x = (800 / 12 * (mtX - curX) + 400);
		y = (600 / 10 * (mtY - curY) + 300);
		printf("x: %d \n", x);
		printf("y: %d \n", y);
		memoryWriteFloat(myProc, mouseX, x);
		memoryWriteFloat(myProc, mouseY, y);
		mouseLClick();
		yrest(1000);
	end
	
	start=1;
	while(start==1) do
		moveTo(desX, desY);	
	end
end
startMacro(main);
Edit:I have no idea why this works like this cause i tried the exact same thing inside the function and i get the error...

Code: Select all

while(start==1) do
		curX = memoryReadInt(myProc, 0x02C84944); --My current X position
		curY = memoryReadInt(myProc, 0x0157C78C); --My current Y position
		if(curX - desX[i] == 0 and curY - desY[i] == 0) then
			i = i+1;
		end
		moveTo(desX[i], desY[i]);	
	end
Last edited by Exempt on Tue Nov 16, 2010 8:28 pm, edited 1 time in total.

User avatar
Administrator
Site Admin
Posts: 5307
Joined: Sat Jan 05, 2008 4:21 pm

Re: Few Lua Questions

#2 Post by Administrator » Thu Jan 28, 2010 5:41 am

Why are you making two tables for the coordinates?

Code: Select all

function pushCoordinates(tab, _x, _y)
  table.insert(tab, {x = _x, y = _y});
end

function doSomething(locations)
  for i,v in pairs(locations) do
    local x = v.x;
    local y = v.y;

    -- now x and y are from each x,y pair in 'locations'
  end
end

local coordinates = {};
pushCoordinates(coordinates, 100, 100);
pushCoordinates(coordinates, 100, 110);

--[[
   You could also do this instead (if you don't want to 'push' each coordinate):

  local coordinates =  {
    { x = 100, y = 100 },
    { x = 100, y = 110 },
  };
]]

doSomething(coordinates);

Exempt
Posts: 197
Joined: Wed Jan 20, 2010 9:55 am

Re: Few Lua Questions

#3 Post by Exempt » Thu Jan 28, 2010 9:50 am

I did it with two table because I'm pretty new to lua. Keeping it simple for me i guess. I'll give that a try though, thanks.

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest