Jump to content

Incorrect Text Being Displayed


deathismyfriend
 Share

Recommended Posts

Hello everyone, I have a problem in my script where the wrong text is being displayed on all objects.

I was hoping to add this to steam for everyone to use. This is my first attempt at using tables. Maybe I made a mistake there ?

 

This script is used to display a text on an entity.

It does display the text but it only displays the last text that has been created.

 

I have checked to make sure that the entities and the buffers are different. Along with checking that the text to be displayed is correct (it prints out the correct text to be displayed on the object but does not show the correct text on screen).

 

Here is the script. Also sorry for the indentation.

 

 


Script.text = ""--string "Text"
Script.color = Vec4()--color "Text Color"
Script.choice = 0--choice "Text Align" center,left,right
Script.textFont = ""--path "Font" "Font (*.ttf):ttf|ttf Files"
Script.sizeFont = ""--int "Font Size"
Script.locationText = Vec2()--vec2 "Text Location"
Script.font = nil

Infos = {}

Info = {
entity = "",
text = "",--string "Text"
color = Vec4(),--color "Text Color"
choice = 0,--choice "Text Align" center,left,right
textFont = "",--path "Font" "Font (*.ttf):ttf|ttf Files"
sizeFont = "",--int "Font Size"
locationText = Vec2(),--vec2 "Text Location"
font = nil,
buffer = nil,

New = function()
info = {}
for k, v in pairs(Info) do
info[k] = v
end
return info
end,

--This function will be called after the world is rendered, before the screen is refreshed.
--Use this to perform any 2D drawing you want the entity to display.
RenderText = function(this, context)
Buffer:SetCurrent(this.buffer)
context:SetFont(this.font)
context:SetColor(this.color)
context:DrawText(this.text, this.locationText.x, this.locationText.y)[/indent]
[indent=1]--I checked the text here to see what should be displayed and it had the correct ones being displayed.[/indent]
[indent=1]--Only the last text to be run through this though was actually being displayed on all entities that this was handling.
this.entity:GetMaterial():SetTexture(this.buffer:GetColorTexture(0),0)
end
}

function Script:Start()
local info = Info.New()
info.entity = self.entity
info.text = self.text
info.color = self.color
info.choice = self.choice
info.textFont = self.textFont
info.sizeFont = self.sizeFont
info.locationText = self.locationText
info.font = Font:Load(self.textFont, self.sizeFont)
info.buffer = Buffer:Create(100,100,1,1)
Infos[self.entity] = info
end

--This function will be called after the world is rendered, before the screen is refreshed.
--Use this to perform any 2D drawing you want the entity to display.
function Script:PostRender(context)
local oldBuffer = Buffer:GetCurrent()
context:SetBlendMode(Blend.Alpha)

for k, v in pairs(Infos) do
Infos[k]:RenderText(context)
end
Buffer:SetCurrent(oldBuffer)
end

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