Page 1 of 1

Few Lua Questions

Posted: Wed Jan 27, 2010 11:40 pm
by Exempt
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

Re: Few Lua Questions

Posted: Thu Jan 28, 2010 5:41 am
by Administrator
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);

Re: Few Lua Questions

Posted: Thu Jan 28, 2010 9:50 am
by Exempt
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.