Jump to content

Text showing up when interacting with entity.


lxFirebal69xl
 Share

Recommended Posts

A long time ago I had this problem with text overlapping itself when you used some entities in the game, then Rick (thanks by the way) came along and fixed this issue. This is the code right now:

 

Inside FPSPlayer.lua right below the default variables:

 

Script.DisplayTimeMax = 4000
local font1 = Font:Load("Fonts/MODERN SERIF ERODED.ttf", 20)

 

In the Start():

 

self.text = ""

 

Inside the UpdateWorld()

 

if pickInfo.entity ~= nil then
  if pickInfo.entity.script ~= nil then
  if pickInfo.entity.script.GetText ~= nil then
   self.text = pickInfo.entity.script:GetText()
   self.DisplayTime = Time:GetCurrent() + self.DisplayTimeMax
  end
 end
   end

 

Under PostRender(context)

 

if self.text ~= "" then
   context:SetBlendMode(Blend.Alpha)
   context:SetFont(font1)

   if self.DisplayTime > Time:GetCurrent() then
 context:SetColor(255,255,255)
 context:DrawText(self.text, 100, 600)
   else
 -- reset
 self.text = ""
   end
  end

 

This is all that was required (back in 2015) to set up the player script, then we had this simple code for the entities:

 

Script.ObjectDescription = "" --string "Object Description"
function Script:GetText()
return self.ObjectDescription
end
function Script:Disable()--in
self.enabled=false
end

 

Now the only problem here is that the hand icon doesn't actually show up, so the player can't interact with it, I tried doing a Use(context) function that called the self.GetText() but that just caused the game to exit out with an error saying:

Script Error
attempt to index local 'self' (a nil value)
Line 8

 

 

So any thoughts as to how I would resolve this issue?

Link to comment
Share on other sites

I don't see anything obvious in the code you posted. Normally I start putting prints all over to figure out if the code in the area that I am looking at is even getting run. For example I'd put a print after each if check for pickInfo, then if all that is getting run, I'd put some prints in PostRender() looking at self.text.

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