40 lines of code. (Mobile game)

Introduction

The other week my friend was working with some python code. He was trying to create a job type game where the object was to pick a job, and then press work. He had done this with fairly sloppy code. (Please note, I am not a python scripter.) He then asked me how I would create this in Roblox. I was not quite sure at the moment, but I knew I was not going to do an “endless” if statement. I then took it as a challenge to create fairly optimized code. (My friend had a little over 50 lines of code.) So, I set that as my goal.

The Game

:iphone: Mobile Game

It’s a Mobile only game. (So beware, because on PC the UI looks trash. :upside_down_face:)

Challenge

Now I’m challenging the finest on Roblox. (Epic Scripter) To join in on this and make a game with less then 50 lines of code. (Note to all you smart role breakers. It needs to be normal code. NO command bar tricks.) Lines must be normal. Do not mush like 5 lines of code into one.

Just some friendly roles for the competition :upside_down_face:

Code Example

local Jobs = {
	["Farmer"] = 120,
	["Bird Watcher"] = 5,
	["Fire Fighter"] = 80,
	["Pizza Maker"] = 500,
	["Scripter"] = 1200
}

local function ClearSelection()
	for _,v in pairs(script.Parent.JobList.ScrollingFrame:GetChildren()) do
		if v:IsA("Frame") then
			v.Select.Text = "🔵"
		end
	end
end

local function ListJobs()
	for key,value in pairs(Jobs) do
		local clone = script.Frame:clone()
		clone.Name = key
		clone.JobName.Text = key
		clone.Parent = script.Parent.JobList.ScrollingFrame
		clone.Select.MouseButton1Click:Connect(function()
			ClearSelection()
			clone.Select.Text = "🟢"
			script.Parent.Parent.Payment.Value = value
		end)
	end
end

ListJobs()

Good luck!

I look forward to seeing what games you can create with only 50 lines of code!

Please let me know if you attempt this. :penguin:

the game isn’t uncopylocked so I’ll just address that snippet of code

local jobs = {
	["Farmer"] = 120,
	["Bird Watcher"] = 5,
	["Fire Fighter"] = 80,
	["Pizza Maker"] = 500,
	["Scripter"] = 1200
}
for k, v in pairs(jobs) do
	local clone = script.Frame:Clone()
	clone.Name = k
	clone.JobName.Text = k
	clone.Parent = script.Parent.JobList.ScrollingFrame
	clone.Select.MouseButton1Click:connect(function()
		for _, v in pairs(script.Parent.ScrollingFrame:GetChildren()) do
			if not v:IsA("Frame") then continue end
			v.Select.Text = v == clone and "🟢" or "🔵"
		end
		script.Parent.Parent.Payment.Value = v
	end)
end
1 Like

Optimization :+1:

very epic!!! :upside_down_face:

3 Likes

I was planning on people making there own games, but now I have the place uncopylocked if you want to go off what I was working on.

by optimization you mean less lines or performance? or does readability matter?

local Jobs = {
	["Farmer"] = 120,
	["Bird Watcher"] = 5,
	["Fire Fighter"] = 80,
	["Pizza Maker"] = 500,
	["Scripter"] = 1200
}

local function ClearSelection() for _,v in pairs(script.Parent.JobList.ScrollingFrame:GetChildren()) do if v:IsA("Frame") then v.Select.Text = "🔵" end end end

local function _()
for key,value in pairs(Jobs) do local clone = script.Frame:clone() clone.Name = key clone.JobName.Text = key clone.Parent = script.Parent.JobList.ScrollingFrame clone.Select.MouseButton1Click:Connect(function() ClearSelection() clone.Select.Text = "🟢" script.Parent.Parent.Payment.Value = value end) end end _()

i made a game with 0 lines. here’s the code


2 Likes

Very nice! I’m impressed! The gameplay is a little hard to understand, but over I think it’s great! Just add a tutorial. :wink:

1 Like

Smashing lines of code together is not what I call optimization. Good try though. :upside_down_face:

I do believe that piece of code could be optimized a bit more via object alias :upside_down_face:

(I’m referring to this)

script.Parent.Parent.Payment.Value = v
2 Likes

Very nice. Thanks for sharing. Now I’m probably going to spend a lot of hours trying to find out how to use/know this.

1 Like

How to become a successful Roblox developer:

Take

and DevX them for $350.

success