Jump to content

It doesn't work for game lua in exe file


khotan
 Share

Recommended Posts

8 hours ago, khotan said:

No, I don't know... It is my first try in Lua for learning because I used before in C++ that work fine.

 

How to setup for startup map in main.lua file ?

When you launch Leadwerks, in your Script folder there is a file called Main.lua. In it you'll be able to change the name of your application's window and change the startup map.

 

import("Scripts/Menu.lua")

--Initialize Steamworks (optional)
--Steamworks:Initialize()

--Initialize analytics (optional).  Create an account at www.gameamalytics.com to get your game keys
--[[if DEBUG==false then
	Analytics:SetKeys("GAME_KEY_xxxxxxxxx", "SECRET_KEY_xxxxxxxxx")
	Analytics:Enable()
end]]

--Set the application title
title="TEMP" --Here, you can change the name displayed on the window.

--Create a window
local windowstyle = 0
local winwidth
local winheight
local gfxmode = System:GetGraphicsMode(System:CountGraphicsModes()-1)
if System:GetProperty("devmode")=="1" then
	gfxmode.x = math.min(1280,gfxmode.x)
	gfxmode.y = Math:Round(gfxmode.x * 9 / 16)
	windowstyle = Window.Titlebar
else
	gfxmode.x = System:GetProperty("screenwidth",gfxmode.x)
	gfxmode.y = System:GetProperty("screenheight",gfxmode.y)
	windowstyle = Window.Fullscreen
end
window = Window:Create(title,0,0,gfxmode.x,gfxmode.y,windowstyle)
if window == nil then
	gfxmode = System:GetGraphicsMode(System:CountGraphicsModes()-1)
	window = Window:Create(title,0,0,gfxmode.x,gfxmode.y,windowstyle)
end

--Create the graphics context
context=Context:Create(window,0)
if context==nil then return end

--Create a world
world=World:Create()

local gamemenu = BuildMenu(context)

--Load a map
local mapfile = System:GetProperty("map","Maps/start.map") --Here, change Mpas/start.map by the name of your first map you want to load (or rename your first map start.map, your choice)
if mapfile~="" then
	if Map:Load(mapfile)==false then return end
	prevmapname = FileSystem:StripAll(changemapname)
	
	--Send analytics event
	Analytics:SendProgressEvent("Start",prevmapname)
	
	gamemenu.newbutton:Hide()
	gamemenu.resumebutton:Show()
	window:HideMouse()
else
	gamemenu:Show()
end

while window:Closed()==false do
	
	--Show game menu when escape key is hit
	if gamemenu:Hidden() then
		if window:KeyHit(Key.Escape) then
			Time:Pause()
			gamemenu:Show()
		end
	end

	--Update events
	while EventQueue:Peek() do
		local event = EventQueue:Wait()
		event = gamemenu:ProcessEvent(event)
	end
	
	--Handle map change
	if changemapname~=nil then
		
		--Pause the clock
		Time:Pause()
		
		--Pause garbage collection
		System:GCSuspend()		
		
		--Clear all entities
		world:Clear()
		
		--Send analytics event
		Analytics:SendProgressEvent("Complete",prevmapname)
		
		--Load the next map
		if Map:Load("Maps/"..changemapname..".map")==false then return end
		prevmapname = changemapname
		
		--Send analytics event
		Analytics:SendProgressEvent("Start",prevmapname)
		
		--Resume garbage collection
		System:GCResume()
		
		--Resume the clock
		Time:Resume()
		
		changemapname = nil
	end	
	
	if gamemenu:Hidden() then
		
		--Update the app timing
		Time:Update()
		
		--Update the world
		world:Update()
		
	end

	--Render the world
	world:Render()
		
	--Render statistics
	context:SetBlendMode(Blend.Alpha)
	if DEBUG then
		context:SetColor(1,0,0,1)
		context:DrawText("Debug Mode",2,2)
		context:SetColor(1,1,1,1)
		context:DrawStats(2,22)
		context:SetBlendMode(Blend.Solid)
	else
		--Toggle statistics on and off
		if (window:KeyHit(Key.F11)) then showstats = not showstats end
		if showstats then
			context:SetColor(1,1,1,1)
			context:DrawText("FPS: "..Math:Round(Time:UPS()),2,2)
		end
	end
	
	--Refresh the screen
	if VSyncMode==nil then VSyncMode=true end
	context:Sync(VSyncMode)
	
end

 

  • Like 1

Just making games for fun. Currently working on T3-L4

Linka logo

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...