Jump to content

Making text not overlap itself.


lxFirebal69xl
 Share

Recommended Posts

So a while ago, I got this script going that makes so the player presses E text will show up, my problem is, if the player clicks on 2 objects at the same time, the text will overlap itself

 

Script

Script.ObjectDescription = "" --String "Object Description"
Script.DisplayTimeMax = 5000 --Int "Display time"
Script.Used = "0"
Script.DisplayTime = 0
Script.DisplayEnabled = false
local font1 = Font:Load("Fonts/True Lies.ttf", 20)
function Script:Use(context)
  self.Used = "1"
  self.CurrentTime = Time:GetCurrent()
  self.DisplayTime = Time:GetCurrent() + self.DisplayTimeMax
end

function Script:PostRender(context)
  if self.Used == "1" then
	  App.context:SetBlendMode(Blend.Alpha)
	  App.context:SetFont(font1)
	  self.DisplayEnabled = true
			   if self.DisplayEnabled == true then
						    if self.DisplayTime > Time:GetCurrent() then
									 App.context:SetColor(255,255,255)
									 context:DrawText(self.ObjectDescription, 100, 600)
							 else
									 self.DisplayEnabled = false
									 self.Used = "0"
							 end
					   end
					   App.context:SetBlendMode(Blend.Solid)
			   end
end

 

 

And my problem

post-13811-0-61042200-1423433693_thumb.png

Link to comment
Share on other sites

I assume you attach this script to all the objects you want to have this in your game? The problem with that is exactly this smile.png. I think you really want this text to be displayed from the player script itself. These object scripts should just contain what you want to say, then the picking should happen in the player script, and from the entity picked you get it's script's ObjectDescription variable and store that in your player script and draw that in post render. This way if you click 2 objects the first one will be overwritten with the second because you are storing it in a player script variable.

 

So in other words these object scripts should only contain data and not the functionality of displaying that data. The player script should get the data from these objects via picking them and be responsible for being the 1 central place to display that data on screen.

 

You can get script data from entities you picked via the script variable they would have (if it's not nil)

 

pickedEntity.script.ObjectDescription

 

[edit]

If your script needs to do something special and unique then put that in a Use function but the act of displaying text on screen isn't special and unique so your objects probably shouldn't do that. Let the player script do that from the object information, especially if an issue like this can happen with your type of game.

Link to comment
Share on other sites

I assume you attach this script to all the objects you want to have this in your game? The problem with that is exactly this smile.png. I think you really want this text to be displayed from the player script itself. These object scripts should just contain what you want to say, then the picking should happen in the player script, and from the entity picked you get it's script's ObjectDescription variable and store that in your player script and draw that in post render. This way if you click 2 objects the first one will be overwritten with the second because you are storing it in a player script variable.

 

So in other words these object scripts should only contain data and not the functionality of displaying that data. The player script should get the data from these objects via picking them and be responsible for being the 1 central place to display that data on screen.

 

You can get script data from entities you picked via the script variable they would have (if it's not nil)

 

pickedEntity.script.ObjectDescription

 

[edit]

If your script needs to do something special and unique then put that in a Use function but the act of displaying text on screen isn't special and unique so your objects probably shouldn't do that. Let the player script do that from the object information, especially if an issue like this can happen with your type of game.

 

Allright, I'll mess around with it, see what happens. Will tell you if I do it.

Link to comment
Share on other sites

So your object file just becomes

 

Script.ObjectDescription = "" --string "Object Description"

function Script:GetText()
return self.ObjectDescription
end

 

 

In the attached FPSPlayer.lua you can search for RLP to find the code I added. There are a few sections and I do begin/end and everything in-between is what I changed.

 

Now only 1 text at a time will display and it'll still go away after so long.

FPSPlayer.lua

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