function GameFunc(message)
	if message == "XML loaded" then
		if PermanentStorage.GetGlobalBool("temp:ScreensaverMode") then
			SendMessage("Screen", "clear children list")
			SendMessage("Screen", "template TankOnlyTemplate")
			SendMessage("Screen", "defineText [variable] Screensaver Tank")
			SendMessage("Screen", "defineText [exitMessageReceiver] post:lua:GameFunc")
			SendMessage("Screen", "defineText [exitMessage] Screen saver done")
			SendMessage("Screen", "create top instance")
			Sound:FadeInTrack("Menu"..PermanentStorage.GetLocalStringOrDef("Screensaver Tank", "1"), 3, true)
		else
			SendMessage("Screen", "clear children list")
			SendMessage("Screen", "template ClickToStartTemplate")
			SendMessage("Screen", "defineText [onClickMessage] Start game")
			SendMessage("Screen", "create top instance")
			SendMessage("Startup progress mover", "report arrival to lua:GameFunc")
			SendMessage("Startup progress mover", "set arrival message Startup progress bar out")
			SendMessage("Startup progress mover", "move to out")
		end
	elseif message == "Screen saver done" then
		CloseApplication()
	elseif message == "Startup progress bar out" then
		--Sound:FadeInTrack("Menu"..PermanentStorage.GetLocalStringOrDef("Current Tank", "1"), 3, true)
		if not ignoreStartupProgressBarOut then
			SendMessage("Startup click to start mover", "report arrival to null")
			SendMessage("Startup click to start mover", "set arrival message null")
			SendMessage("Startup click to start mover", "move to in")
		end
	elseif message == "Start intro key pressed" then
		if PermanentStorage.GetGlobalBoolOrDef("dev", true) then
			SendMessage("lua:GameFunc", "Start intro")
		end
	elseif message == "Start intro" then
		SendMessage("Screen", "clear children list")
		SendMessage("Screen", "template IntroTemplate")
		SendMessage("Screen", "create top instance")
		SendMessage("last intro action", "set delay 2.0")
		SendMessage("last intro action", "set message on post:lua:GameFunc/Exit intro")
		SendMessage("last intro action", "report to Click to start sensor")
		SendMessage("Screen", "template BrighteningTemplate")
		SendMessage("Screen", "create top instance")
		Sound:FadeOutTrack("Menu"..PermanentStorage.GetLocalString("Current Tank"), 1)
		Sound:FadeInTrack("Intro", 2, true)
	elseif message == "Exit intro" then
		SendMessage("view port moving", "report arrival to null")
		SendMessage("view port moving", "set arrival message null")
		SendMessage("view port moving", "move to in")
		SendMessage("Zooming little viewport", "change zoom to original")
		SendMessage("last text ramka", "change alpha to 0.0")
		SendMessage("Build up your Fishdom", "change alpha to 0.0")
		SendMessage("last intro action", "set delay 0.5")
		SendMessage("last intro action", "set message Click to start main menu")
		SendMessage("last intro action", "report to post:lua:GameFunc")
		PermanentStorage.SetLocalBool("black screen", false)
		Sound:PlaySample("intro_last_screen_zoom")
		Sound:FadeOutTrack("Intro", 1)
		Sound:FadeInTrack("Menu"..PermanentStorage.GetLocalString("Current Tank"), 3, true)
	elseif message == "Start game" then
		SendMessage("Screen", "template DarkeningTemplate")
		SendMessage("Screen", "defineText [receiver] post:lua:GameFunc")
		SendMessage("Screen", "defineText [message] Click to start main menu")
		SendMessage("Screen", "create top instance")
		PermanentStorage.SetLocalBool("black screen", true)
	elseif message == "Click to start main menu" then
		ignoreStartupProgressBarOut = true
		SendMessage("Screen", "clear children list")
		ignoreStartupProgressBarOut = nil
		if PermanentStorage.GetGlobalBoolOrDef("Ask player name", true) then
			SendMessage("lua:MainMenuFunc", "Create main menu")
			SendMessage("lua:GameFunc", "Ask first player name")
		else
			SendMessage("lua:MainMenuFunc", "Enter main menu")
		end
		if PermanentStorage.GetLocalBool("black screen") then
			SendMessage("Screen", "template BrighteningTemplate")
			SendMessage("Screen", "create top instance")
		end
	elseif message == "Ask first player name" then
		SendMessage("Main menu modal dialog", "instantiate FirstPlayerNameEditTemplate")
		SendMessage("Player name mover", "report arrival to null")
		SendMessage("Player name mover", "set arrival message null")
		SendMessage("Player name mover", "move to in")
	elseif message == "Enter your name ok pressed" then
		local newName = SendMessageReply("Player name edit", "get value")
		if newName ~= "" then
			local oldName = PermanentStorage.GetActivePlayerName()
			if oldName == newName then
				PermanentStorage.RenamePlayer(oldName, "["..oldName.."]")
			end
			PermanentStorage.SetGlobalBool("Ask player name", false)
			PermanentStorage.CreatePlayer(newName)
			PermanentStorage.DeleteInactivePlayers()
			PermanentStorage.SetLocalString("Current Tank", "1")
			Sound:FadeInTrack("Menu"..PermanentStorage.GetLocalString("Current Tank"), 1.0, true)
			SendMessage("post:lua:GameFunc", "Start intro")
		end
	else
		assert(false, "Unknown message "..message)
	end
end

function BetaFunc(message)
	if message == "Game field to main screen" then
		SendMessage("post:lua:BetaFunc", "Duplicate player if hour")
	elseif message == "Main menu to main screen" then
		SendMessage("post:lua:BetaFunc", "Duplicate player if hour")
	elseif message == "Main screen to shop" then
		SendMessage("post:lua:BetaFunc", "Duplicate player if hour")
	elseif message == "Main screen to game field" then
		SendMessage("post:lua:BetaFunc", "Duplicate player if hour")
	elseif message == "Shop to main screen" then
		SendMessage("post:lua:BetaFunc", "Duplicate player if hour")
	elseif message == "Duplicate player if hour" then
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			local totalTime = PermanentStorage.GetLocalFloatOrDef("Total time", 0)
			local backuped = PermanentStorage.GetLocalBoolOrDef("Was one hour backup", false)
			if totalTime > 3600 and not backuped then
				PermanentStorage.SetLocalBool("Was one hour backup", true)
				PermanentStorage.BackupActivePlayer("  (1h)")
				WriteToLogColor("One hour checkpoint!", "Red")
			end
		end
	elseif message == "Duplicate player won cup" then
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			local tankId = PermanentStorage.GetLocalString("Current Tank")
			local cup = PermanentStorage.GetLocalString(tankId.." Cup")
			if cup == "Bronze" then
				PermanentStorage.BackupActivePlayer(tankId.." B")
			elseif cup == "Silver" then
				PermanentStorage.BackupActivePlayer(tankId..".S")
			elseif cup == "Gold" then
				PermanentStorage.BackupActivePlayer(tankId..":G")
			else
				assert(false)
			end
		end
	elseif message == "Clear cup time" then
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			PermanentStorage.SetLocalFloat("Cup time", 0)
			WriteToLog("Cup time reset")
		end
	elseif message == "Commit" then
		if PermanentStorage.GetGlobalBoolOrDef("betaLog", false) then
			WriteToLog("autosave...")
		end
		PermanentStorage.Commit()
	else
		assert(false, "Unknown message "..message)
	end
end