Jump to content

Text showing up when interacting with entity.

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


Under PostRender(context)


if self.text ~= "" then

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


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
function Script:Disable()--in


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?

Share this post

Link to post

You say it uses self.GetText()... Shouldn't it be self:GetText() with a : not a .


I was right, it was obvious...that fixed the error popping up, but the text doesn't show up.

Share this post

Link to post

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.

Share this post

Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

  • Create New...