3D2D : draw.DrawText(Variable, .. , .. , .. , .. )

Hi
First sorry for my English , i’m French ° ^ °.

So i was trying to put a Variable on a draw.DrawText
and i tried :

and

But it do a error message on the console , or it just draw “Water:WaterAmount” … etc

I know that i probably did big misstakes but i’m clearly a noob at programming ^^’ .

If you still didn’t understood , I didn’t succeed to do someting like this :

https://image.noelshack.com/fichiers/2017/44/2/1509409414-schema-3d2d-text-and-une-variable.png

By The Way : If you know French , a French answer could be awesome to better understand <3

To pass a variable as an argument to a function, just put its name:
[lua]function x(arg)
print(arg)
end

local y = 10

x(y) – prints 10[/lua]

Also you didn’t upload your image.

I do not really understand how to adapt it ^^’ .

Is it :

cl_init.lua



function ENT:Draw()
	self.Entity:DrawModel()


	cam.Start3D2D(self:GetPos() + Vector(0,-15,25) , Angle(0,0,75) , 0.1)


		draw.DrawText("Conteneur D'eau","TheDefaultSettings",-10,0,Color(120,120,255),1,1)
		draw.DrawText("Water:"WaterAmount,"TheDefaultSettings",-120,80,Color(255,127,80))
		




	cam.End3D2D()
end


shared.lua



local WaterAmount = 10


Because actually it makes a bugged map , and still no what i wanted. :confused:

It’s called concatenation

You concatenate the variable to a string, in Lua concatenate is done using two periods, I would try


" "..<variable>

YESSSS ! Thanks guys : P !

so finnally the “local WaterAmount = 20” is in cl_init.lua . THANKS ! : P

But now there is still this map bug :

https://image.noelshack.com/fichiers/2017/44/2/1509417602-buggg.png

with this script :



include("shared.lua")

local WaterAmount = 20

surface.CreateFont( "TheDefaultSettings", {
	font = "Arial", -- Use the font-name which is shown to you by your operating system Font Viewer, not the file name
	extended = false,
	size = 50,
	weight = 500,
	blursize = 0,
	scanlines = 0,
	antialias = true,
	underline = false,
	italic = false,
	strikeout = false,
	symbol = false,
	rotary = false,
	shadow = false,
	additive = false,
	outline = false,
} )

function ENT:Draw()
	self.Entity:DrawModel()

	cam.Start3D2D(self:GetPos() + Vector(0,-15,25) , Angle(0,0,75) , 0.1)

		draw.DrawText("Conteneur D'eau","TheDefaultSettings",-10,0,Color(120,120,255),1,1)
		draw.DrawText("Water:"..WaterAmount,"TheDefaultSettings",-120,80,Color(255,127,80))
		

	cam.End3D2D()
end


If you could help me ^^’ .

Ok so finnally everything is ok . Thanks .