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

How does one give evolving creatures senses?

I recently started using Roblox Studio as a sandbox to practice coding and making projects. I have been experimenting with 'evolving' creatures lately. https://www.roblox.com/games/3384015828/Evolving-Floppy-Dudes This is my current project. Currently, these things evolve to run forward by changing the RotVelocity of their limbs. It sort of works, but I realized they are entirely blind. I could give them 'senses', as in they could detect their base orientation, but I don't know how I would have them react to their senses. Currently, they act with this code.

while true do
	for i = 1, commandnum do
		for x,child in pairs(script.Parent.values:GetChildren()) do
			if string.match(child.Name,"BLNval" .. i) == "BLNval" .. i then
				script.Parent.BLN.noodle.RotVelocity = child.Value
			end
		end
		for x,child in pairs(script.Parent.values:GetChildren()) do
			if string.match(child.Name,"BRNval" .. i) == "BRNval" .. i then
				script.Parent.BRN.noodle.RotVelocity = child.Value
			end
		end
		for x,child in pairs(script.Parent.values:GetChildren()) do
			if string.match(child.Name,"FLNval" .. i) == "FLNval" .. i then
				script.Parent.FLN.noodle.RotVelocity = child.Value
			end
		end
		for x,child in pairs(script.Parent.values:GetChildren()) do
			if string.match(child.Name,"FRNval" .. i) == "FRNval" .. i then
				script.Parent.FRN.noodle.RotVelocity = child.Value
			end
		end
		for x,child in pairs(script.Parent.values:GetChildren()) do
			if string.match(child.Name,"wait" .. i) == "wait" .. i then
				wait(child.Value)
			end
		end
		script.Parent.values.XDistance.Value = script.Parent.base.Position.X - InitialPosition
	end
end
--for the number of commands this creature has do
--	set limb RotVelocity to corresponding RotVelocity value
--	wait for corresponding wait time

The creatures have four limbs connected by ball socket joints labeled 'BLN' as in "Back Left Noodle". Their traits vary every time they spawn- traits like wait time, number of commands in walk cycle, and velocity of limb. The game takes the top 15 out of 30 that covered the most X distance and spawns a copy of each of them. I could use some conceptual help on how this move script should be designed, since at the moment they blindly move, then wait on repeat. Also, this is my first post and I am new to this scripting stuff so forgive me if it is messy.

EDIT: I suppose I should clarify in that the only way I've found to make the creatures vary is by using values in the workspace that the script can use to communicate with the next round of creatures. In other words, I don't know how to modify the script itself to evolve, only random number values.

1 answer

I got help from the discord. I am going to redesign my code completely. I will store 'genes' in a string value that the code can read with a table of functions. This solved everything.

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