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.
It’s a Mobile only game. (So beware, because on PC the UI looks trash. )
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
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!
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
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 _()