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

How to compare values to spot a different one and to use the majority in values?

https://gyazo.com/bb99927f1c95b611e1120f1e4c8254ed

The Processor (Number) calculates the value, since i want to be precise, the redundancy processor will compare the values between all of the processors, and the processors with the most results, get that result selected as the right one, so it can be precise, and turn the leds on and off depending on the values, so, how do i make a script that goes in every processor folder to compare it's values to other processors? (https://www.youtube.com/watch?v=N5faA2MZ6jY 0:52 for explanaiton of what i want to make)

So, i need to check the right value that is found in the majority of the processors, i need to make it modular (i can duplicate the Processor (NUMBER) as many times as i want and the main redundancy processor will check each values and return the precise values and light on-off leds

1 comment

0

What values can the bits be (are they single number binary or decimal)? I'm very interested so I want to know more before I try to formulate an answer.

1 answer

Have a processor folder which contains all the processors. Iterate through it and add the intValues (assuming that's how you store the "bits") into an array and find the mode of the array which is the majority value.

local Processors = script.Parent.Processors
local Bits = {}

function getProcessorBits() -- gets the bits and inserts into the table
	for _,v in pairs(Processors:GetChildren()) do
		if string.match(v.Name, "Processor") then
			table.insert(Bits, v.intValue.Value)
		end
	end
end

function flushProcessorBits() -- clears the table of all bits
	for i,v in pairs(Bits) do
		Bits[i] = nil
	end
end

function findMajorityBit(Bits) -- finds the most common bit, the modal class
	local Integers = {}
	local Mode = 0
	for i,v in pairs(Bits) do
		if Integers[v] then
			Integers[v] = Integers[v] + 1
		elseif not Integers[v] then
			Integers[v] = 1
		end
	end
	for i,v in pairs(Integers) do
		--print(v.." "..i) -- i used this to check if the mode function was working in studio
		if v > Mode then
			Mode = i
		end
	end
	return Mode
end

You'll have to implement everything else, but those three functions are the core functions.

3 comments

0

Thank you!

0

There is only one problem tho, so, i need to get the most returned value in all processors, and it needs to spot the processor with the flawed returns, this means: like getting the most returned processors, and then checking every processors if they have the same most returned value, and running a function, right now i am trying to see to get it right

0

If you want to see what processor has what bit, you'll have to modify the script to use a dictionary instead then. I'm using an array here which is nameless/does not identify processors.

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