Basic Info

From SolarStrike wiki
Jump to: navigation, search

Script Layout

Each script in MicroMacro 2 has three functions to control the flow of execution:

macro.init(...) This is the function called at the start of the script. It accepts any command-line arguments passed to it and should not return any results. This is where you want to do your setup.

macro.main(dt) This is your main loop. This will be called ~1,000 times per second. It accepts one parameter (delta time) and should return true as long as you want to continue execution. If you return false, execution ends. Unlike older versions of MicroMacro, you do not want to put a while-loop here and do not need to put a system rest command to reduce CPU usage.

macro.event(e, ...) All events will be passed off to this function. The first parameter is the event type as a string. The number of additional arguments passed in depend on the event type.


Example

function macro.init()
	print("Hello world!");
	print("Press SPACE BAR to quit");
end

local running = true;
function macro.main()
	return running;
end

function macro.event(e, data1, data2, data3, data4)
	if( e == "keypressed" ) then
		if( data1 == key.VK_SPACE ) then
			print("Space bar was pressed. Quitting.");
			running = false;
		end
	end
end