generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Re: BrickColor.new()

Previous Thread :: Next Thread 
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
26 May 2014 01:29 PM
How can I add a .Name or .Color to this like you can do with roblox lua

local BrickColors = {
Blue = "Blue";
Red = "Red";
Grey = "Grey"
}
local BrickColor = {
new = function(Color)
if BrickColors[Color] then
return BrickColors[Color]
end
return BrickColors["Grey"]
end
}
print(BrickColor.new("Red"))
print(BrickColor.new("Blue"))
print(BrickColor.new("Grey"))
print(BrickColor.new("nac"))
Report Abuse
FreeScriptMaker is not online. FreeScriptMaker
Joined: 29 Nov 2013
Total Posts: 2275
26 May 2014 01:36 PM
do
local function createNewColor(colorName)
local newColor = {
["Name"] = colorName;
}
return newColor
end

BrickColors = {
["Blue"] = createNewColor("Blue");
["Red"] = createNewColor("Red");
["Grey"] = createNewColor("Grey");
}
end

local BrickColor = {
new = function(Color)
if BrickColors[Color] then
return BrickColors[Color]
end
return BrickColors.Grey;
end
}

local brickColor = BrickColor.new("Blue")
print(brickColor.Name) --> Blue
Report Abuse
FreeScriptMaker is not online. FreeScriptMaker
Joined: 29 Nov 2013
Total Posts: 2275
26 May 2014 01:41 PM
Or you could do this to prevent people from changing things

do
local function createNewColor(colorName)
local newColor = {
["Name"] = colorName;
}
return newColor
end

local BrickColors = {
["Blue"] = createNewColor("Blue");
["Red"] = createNewColor("Red");
["Grey"] = createNewColor("Grey");
}

BrickColor = {
new = function(Color)
if BrickColors[Color] then
return BrickColors[Color]
end
return BrickColors.Grey;
end
}
end

local brickColor = BrickColor.new("Blue")
print(brickColor.Name) --> Blue
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
26 May 2014 02:17 PM
I need it to still work if I said
print(BrickColor.new("Blue")) -->Blue
Because thats how roblox brick colors work (Thats why you can compare them as BrickColor.new("color") == BrickColor.new("color")
Does what you posted do that?
I can't test right now, on myiPhone
Report Abuse
FreeScriptMaker is not online. FreeScriptMaker
Joined: 29 Nov 2013
Total Posts: 2275
26 May 2014 02:19 PM
It doesn't do that right now give me a few minutes and I will work on that.
Report Abuse
FreeScriptMaker is not online. FreeScriptMaker
Joined: 29 Nov 2013
Total Posts: 2275
26 May 2014 02:23 PM
Actually the way you thought they compare colors is wrong. They actually compare to see if the two tables are matching. So the code I already posted should work fine.
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 02:39 PM
local color = {};
setmetatable(color, {__index = colors});

function color.new(str, c3)
local tbl = {
Name = str;
Color = Color3.new(blah);
etc...
};
local obj = newproxy(true); --treat the color as a userdata
local mt = getmetatable(obj);
mt.__index = tbl;
mt.__tostring = str;
return obj
end

Something like that
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
26 May 2014 02:40 PM
mt.__tostring = function() return str; end;
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
30 May 2014 12:14 AM
@Cnt
The program Im running it in says newproxy is a nil value
I probably did the script wrong but it can't use newproxy anyway

Ideas?


local BrickColors = {
Blue = {Name = "Blue"};
Red = {Name = "Red"};
Grey = {Name = "Grey"}
}
local BrickColor = {
new = function(Color)
if BrickColors[Color] then
return BrickColors[Color]
end
return BrickColors["Grey"]
end
}
print(BrickColor.new("Red") == BrickColor.new("Red")) -->true
print(BrickColor.new("Blue").Name) -->Blue
print(BrickColor.new("Grey").Name) -->Grey
print(BrickColor.new("nac").Name) -->Grey
print(BrickColor.new("Blue")) -->table:
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
30 May 2014 12:17 AM
comparing..

"print(BrickColor.new("nac").Name) -->Grey"
"print(BrickColor.new("Blue")) -->table: "--forgot Name
print(BrickColor.new("nac").Name) -->Grey
print(BrickColor.new("Blue").Name) -->Blue
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
30 May 2014 12:22 AM
@Island
Um, thats basically what I just said without the script
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
30 May 2014 12:22 AM
Then just use a table, although it's not really a good idea since they can insert values into it.

local color = {};
setmetatable(color, {__index = colors});

function color.new(str, c3)
local tbl = {
Name = str;
Color = Color3.new(blah);
etc...
};
local obj = setmetatable({}, {});
local mt = getmetatable(obj);
mt.__index = tbl;
mt.__tostring = str;
return obj
Report Abuse
islandmaker2012 is not online. islandmaker2012
Joined: 07 Nov 2012
Total Posts: 9327
30 May 2014 12:23 AM
local BrickColors = {
Blue = "Blue";
Red = "Red";
Grey = "Grey"
}
oldBc = BrickColor.new
local BrickColor = {
new = function(Color)
if BrickColors[Color] then
return oldBc(BrickColors[Color])
end
return oldBc(BrickColors["Grey"])
end
}
print(BrickColor.new("Red"))
print(BrickColor.new("Blue"))
print(BrickColor.new("Grey"))
print(BrickColor.new("nac"))

--idk
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
30 May 2014 12:30 AM
I have no idea what I'm doing .3.
Error attempt to call a string value

local color = {};
setmetatable(color, {__index = colors});

function color.new(str, c3)
local tbl = {
Name = str;
TESTPROP = c3
};
local obj = setmetatable({}, {});
local mt = getmetatable(obj);
mt.__index = tbl;
mt.__tostring = str;
return obj
end

print(color.new("blue", "hi"))
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
30 May 2014 12:34 AM


local color = {};
setmetatable(color, {__index = colors});

function color.new(str, c3)
local tbl = {
Name = str;
TESTPROP = c3
};
local obj = setmetatable({}, {});
local mt = getmetatable(obj);
mt.__index = tbl;
mt.__tostring = function() return str; end;
return obj
end

print(color.new("blue", "hi"));
Should output blue
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
30 May 2014 12:46 AM
Thank you very much! :)

local create = {}
setmetatable(create, {__index = create});
function create.color(name, invert)
local tab = {
Name = name;
Invert = invert
}
local Color = setmetatable({}, {})
local metab = getmetatable(Color)
metab.__index = tab
metab.__tostring = function() return name end
return Color
end
a = create.color("blue", "red") --just for testing
print(a)
print(a.Name)
print(a.Invert)
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image