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 » Scripters
Home Search
 

Re: How do I make a constant in Roblox

Previous Thread :: Next Thread 
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
07 Dec 2014 11:49 PM
its possible
Report Abuse
Osyris is not online. Osyris
Joined: 27 Oct 2007
Total Posts: 4321
07 Dec 2014 11:55 PM
The concept of a constant is to be more memory efficient than a variable.
Any hackery to make a 'constant' with Lua, would only result in less memory efficiency than just a variable.

It really isn't practical.

But I guess you could do stuff like constantly set the variable or make it a table and play with metamethods.
Report Abuse
ChiefDelta is not online. ChiefDelta
Joined: 05 Nov 2010
Total Posts: 13071
08 Dec 2014 12:07 AM
idc about efficency i want to make define() like there is in PHP so i guess ill be playing with metamethods than
Report Abuse
128GB is not online. 128GB
Joined: 17 Apr 2014
Total Posts: 8056
08 Dec 2014 02:32 AM
from a google search this is what I understand define() in php does, I don't know php so sorry if I'm wrong


This is more of an idea, because the way I did the 'case' function doesn't really work well so yah some combos are skipped


local function case(n, x, v)
for y = #n, x, -1 do
getfenv()[n:sub(1, y - 1) .. n:sub(y, y):upper() .. n:sub(y + 1)] = v
end
if #n > x then
case(n:sub(1, x):upper() .. n:sub(x + 1), x + 1, v)
end
end

local function define(n, v, c)
if c then
getfenv()[n:lower()] = v
case(n:lower(), 1, v)
else
getfenv()[n] - v --_G[n] = v in not roblox lua
end
end

define("test", "Hello world!", true)
define("another", "Good bye!")

print(test) -->Hello world!
print(TEst) -->Hello world!
print(tEsT) -->nil, shouldn't be, but is because of the way I did it

print(another) -->Good bye!
print(ANoThER) -->nil
Report Abuse
ohno1112 is not online. ohno1112
Joined: 23 Mar 2013
Total Posts: 833
08 Dec 2014 05:27 AM
or, just make a variable and don't change it at all.
Report Abuse
eLunate is not online. eLunate
Joined: 29 Jul 2014
Total Posts: 13268
08 Dec 2014 10:21 AM
I just declare my constants in Lua as local variables at the start of the script, all uppercase.

If you really need constants, you can do trickery with the function environment and the __index + __newindex metamethods.
This assumes that you mean a const like a Readonly value, that is.
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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