Jump to content

[Leadwerks 3 Indie Edition] Game crashes when setting font


X54321
 Share

Recommended Posts

I'M BACK! I'm trying to load a special font for the health percentage in my game; Loading the font goes by smoothly, but when I actually try to set the font it crashes. I know the font isn't nil (I tested it) and it can't be the font I'm using because it's the default font, except with a different size. Anyways, here's some code:

 

local window = Window:GetCurrent()
local forward = 0
local strafe = 0
local angle = 0
local firing = false
local shootTimer = 0
local health = 100
local pickInfo = PickInfo()

function Script:Start()
self.w1 = Texture:Load("Materials/HUD/gun_overlay.tex")
self.w1f = Texture:Load("Materials/HUD/gun_overlay_02.tex")
self.ch = Texture:Load("Materials/HUD/crosshair.tex")
self.hb = Texture:Load("Materials/HUD/healthbar.tex")
self.entity:SetKeyValue("weapon", "blaster")
self.entity:SetKeyValue("type", "player")
self.font = Font:Load("Materials/Fonts/arial.ttf",36)

local material = Material:Create()
material:SetBlendMode(5)
self.entity:SetMaterial(material)
material:Release()
end
function Script:UpdateWorld()
window = Window:GetCurrent()
angle = angle - dx * 0.25
local jump = 0
if window:KeyDown(Key.Space) and self.entity:GetAirborne() == false then
 jump = 10
end
if window:MouseHit(1) and firing == false and self.entity:GetKeyValue("weapon") ~= "none" then
 firing = true

 local p0 = self.entity:GetChild(0):GetPosition(true)
 local p1 = Transform:Point(0,0,20,self.entity:GetChild(0),nil)

 self.entity.world:Pick(p0,p1, pickInfo, 0, true)
 if pickInfo.entity ~= nil then
  if pickInfo.entity:GetKeyValue("type") == "enemy" then
   pickInfo.entity:SetKeyValue("hurt", "true")
  end
 end

end
if firing == true and shootTimer < 24 then
 shootTimer = shootTimer + 1
elseif firing == true and shootTimer == 24 then
 shootTimer = 0
 firing = false
end
forward = (window:KeyDown(Key.W) and 1 or 0)*6 - (window:KeyDown(Key.S) and 1 or 0) * 6
strafe = (window:KeyDown(Key.D) and 1 or 0)*6 - (window:KeyDown(Key.A) and 1 or 0) * 6
self.entity:SetInput(angle, forward, strafe, jump, false)
onGround = false
end
function Script:PostRender(context)
context:SetBlendMode(Blend.Alpha)
context:SetColor(1,1,1,1)
context:DrawImage(self.ch, 400 - 16, 300 - 16)
--context:DrawImage(self.hb, 0, 600 - 104)
context:SetFont(self.font)
context:DrawText("Health: "..health.."%", 160, 600 - 72)
end

Link to comment
Share on other sites

I get this error on line 26:

Quote

 

attempt to perform arithmetic on global 'dx' (a nil value)

 

That's because I have custom variables for Delta mouse coordinates in App.lua. You can comment that out, it just controls the camera movement. The camera's script also references one of those variables.

Link to comment
Share on other sites

And you are sure that in PostRender() self.font is not nil? I just want to make sure you didn't just check it in Start() after it was loaded. Also check it in PostRender() before it renders it. That might at least help figure something out. My guess would be it has to be nil in PostRender() to crash the engine.

Link to comment
Share on other sites

And you are sure that in PostRender() self.font is not nil? I just want to make sure you didn't just check it in Start() after it was loaded. Also check it in PostRender() before it renders it. That might at least help figure something out. My guess would be it has to be nil in PostRender() to crash the engine.

 

Yes, I have already stated it isn't nil. I did both of the things you mentioned, and it was not nil.

Link to comment
Share on other sites

[/size][/font][/color]

 

You didn't mention specifically at what time it wasn't nil so was just making sure you tried that. I'll be working with fonts here in the next hour or so, so I'll see what comes of it and let you know.

 

OK, sounds like a plan.

Link to comment
Share on other sites

I just downloaded a new font and it worked in PostRender() for me without a problem. Are you using the beta version from Steam of LE 3.1 though because that's what I"m using.

 

Hmm, maybe it's just a problem that's fixed in the beta version. I may or may not switch to the beta version later, is there any risk of corrupting my project?

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...