Render Text ? :o

Place to get help with not working mods / modding interface.
Post Reply
PanTobi
Fast Inserter
Fast Inserter
Posts: 202
Joined: Fri Feb 05, 2016 12:34 am
Contact:

Render Text ? :o

Post by PanTobi »

Hey, how to render Text on Screen ? :D

i found this function:

Code: Select all

/c
local entity = game.player.selected
	rendering.draw_text 
		{
			text = "TEST", 
			scale = 1.4,
			color = {255,0,0},
			surface = entity.surface, 
			target = entity
		}
i wanted to move Text UP but and right but im not sure how to use:

Code: Select all

target_offset = right = {1.0, 0.0}
+ Is it possible to use TEXT Formating like for Chat and BP Library?
im asking about Font and Color TAGs :D
[font=default-large-bold][color=255,190,255]🅃🄾🄱🄸[/color][/font]

User avatar
Cooldude2606
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Sat Sep 16, 2017 9:04 pm
Contact:

Re: Render Text ? :o

Post by Cooldude2606 »

LuaRendering is used to render things into the game world. If you are wanting to place text onto the players screen then you will want to use a GUI.

There is a gui position referenced by LuaPlayer.gui.screen which you can then add labels onto.
Once you add a label onto a player's screen you can change its position with LuaGuiElement.location to be where you want it.
With GUI labels you can set their style to allow rich text elements with LuaGuiElement.style.rich_text_setting.

However, if you are wanting it to be connected to an entity then you are right to use LuaRendering.
To use target_offset you need to include it in the table you are passing to draw_text.
Like all positions in the game, a vector of {1,1} will be down and right so you will want {1,-1} or some scalar of it.
The vector will also be in number of tiles, you can see the tile grid with the debug option (f4) "show-tile-grid".
Color should be done with the color property, however there is no way to make rich text work with LuaRendering see this post.
--- Developer for Explosive Gaming factorio community. Find our code on GitHub. Please contact me via our Discord. ---

PanTobi
Fast Inserter
Fast Inserter
Posts: 202
Joined: Fri Feb 05, 2016 12:34 am
Contact:

Re: Render Text ? :o

Post by PanTobi »

I just want to create some Text over some objects like for example:
427520_20200610004815_1.png
427520_20200610004815_1.png (1.44 MiB) Viewed 1105 times

Code: Select all

/c
local entity = game.player.selected
	rendering.draw_text 
		{
			text = "Sell Circuits", 
			scale = 1.4,
			color = {255,120,0},
			surface = entity.surface, 
			target = entity,
			target_offset = {-1.4, -3.0}
		}
This code works fine... but egh :c...
its hard to setup Text in correct place... i was trying 10 times before it was in center and over market :D

Bfff ok... Topic can be closed or something... idk...
im just gonna fuck with draw_text function...

I already tested and i can use this function multiple times on single entity so if i want multi colored text...
it will take while but i can do it with this function xD

User avatar
Cooldude2606
Long Handed Inserter
Long Handed Inserter
Posts: 86
Joined: Sat Sep 16, 2017 9:04 pm
Contact:

Re: Render Text ? :o

Post by Cooldude2606 »

PanTobi wrote:
Tue Jun 09, 2020 9:51 pm
its hard to setup Text in correct place... i was trying 10 times before it was in center and over market :D
What might be useful is if you use "alignment" with draw_text.
The default is to align the left corner, if you set the value to "center" then you dont need to worry about the x offset.
PanTobi wrote:
Tue Jun 09, 2020 9:51 pm
I already tested and i can use this function multiple times on single entity so if i want multi colored text...
Calling the function multiple times wont remove the old ones that were added.
So you will want to use LuaRending.destroy to stop it from possibly lagging the game.
( I once made this mistake with map tags, after a few hours of game play there were hundreds of tags on the map all overlapping )
--- Developer for Explosive Gaming factorio community. Find our code on GitHub. Please contact me via our Discord. ---

Post Reply

Return to “Modding help”