View Single Post
Old 06-17-2009   #937
Ravengus
Newbie
 
Join Date: Jan 2007
Posts: 7
Default Re: PitBull 4.0

hey,

I've converted all my dogtag-Code to LuaText-Code, but I noticed that I needed the SeparateDigits() function from DogTag, so I copied the code from DogTag to LuaText and it works just fine, can you add it to the default ScriptEnv.lua?

Code:
local function SeparateDigits(number, thousands, decimal)
		local int = math.floor(number)
		local rest = number % 1
		if int == 0 then
			t[#t+1] = 0
		else
			local digits = math.log10(int)
			local segments = math.floor(digits / 3)
			t[#t+1] = math.floor(int / 1000^segments)
			for i = segments-1, 0, -1 do
				t[#t+1] = thousands
				t[#t+1] = ("%03d"):format(math.floor(int / 1000^i) % 1000)
			end
		end
		if rest ~= 0 then
			t[#t+1] = decimal
			rest = math.floor(rest * 10^6)
			while rest % 10 == 0 do
				rest = rest / 10
			end
			t[#t+1] = rest
		end
		local s = table.concat(t)
		for i = 1, #t do
			t[i] = nil
		end
		return s
	end
ScriptEnv.SeparateDigits = SeparateDigits
All code directly taken from LibDogTag =)

Bye, Ravengus.
Ravengus is offline   Reply With Quote