Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Why won't this print anything?

Somehow this does not print anything at all. It doesn't give me an error message. Pls halp

local x = 2 --x is 2
local msg = "A" --msg is A
local msgbyte = string.byte(msg)--msgbyte is 65

for i = 0, 7 do --All exponents of 2 in the basic binary notation.
	x = x^i --Get the i'th power of x
	if msgbyte/x == math.floor(1) then --if 65 divided by 64 is about 1, then
		print(i) --print the exponent, or the iteration
		end
	x = 2 --Set x back to 2 for the next iteration
end

1 answer

You put the math.floor in the wrong place. You said math.floor(1) which is unnecessary because it will always return 1. You should have said math.floor(msgbyte/x) == 1, which rounds msgbyte/x down towards negative infinity. I cleaned up the code for you:

local x = 2 --x is 2
local msg = "A" --msg is A
local msgbyte = string.byte(msg)--msgbyte is 65

for Exp = 0, 7 do --All exponents of 2 in the basic binary notation.
	local newx = x ^ Exp --Get the Exp'th power of x
	if math.floor(msgbyte / newx) == 1 then
		print(i) --print the exponent, or the iteration
	end
end

Hope this helped!

This discussion is preserved as it was. New answers, comments, and votes are closed.