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: Is using boolValues, integerValues, bad?

Previous Thread :: Next Thread 
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
12 Apr 2016 05:43 PM
I've heard that they are easily manipulated by exploiters, but I was wondering whether overall if I should use them if they are an option.

Otherwise, should I try to stay as far away from them as possible?
Report Abuse
goro7 is not online. goro7
Joined: 01 Jul 2009
Total Posts: 735
12 Apr 2016 05:45 PM
I use them so much it is not even funny. They are practically required for a ROBLOX game.
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
12 Apr 2016 05:45 PM
I use them in ReplicatedStorage if I want the client to have some read-only information for some reason.
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
12 Apr 2016 05:49 PM
They could be easily manipulated unless they're server sided
Report Abuse
jode6543 is not online. jode6543
Joined: 16 Jun 2009
Total Posts: 5363
12 Apr 2016 06:04 PM
They can't be manipulated if you have filtering enabled. That being said, there isn't a huge reason to use them. Let's say you were making a building game, and wanted to store the owner of each brick. Rather than creating an ObjectValue that references their player, a better solution to just create a ModuleScript that holds all of this information:

local OwnerMngr = {}
local ownedParts = {}

function OwnerMngr.setOwner(part, owner)
if part:IsA("BasePart") and owner:IsA("Player") then
ownedParts[part] = owner
end

function OwnerMngr.getOwner(part)
return ownedParts[part]
end

--more stuff

return OwnerMngr

.. and require it when you need it.
Report Abuse
RecurringNightmare is not online. RecurringNightmare
Joined: 05 Jul 2012
Total Posts: 15336
12 Apr 2016 06:09 PM
What he said ^ Recording the introduction to my FE (Filtering Enabled) tutorial series right now.
Report Abuse
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
12 Apr 2016 06:32 PM
@jode

function OwnerMngr.setOwner(part, owner)
if part:IsA("BasePart") and owner:IsA("Player") then
ownedParts[part] = owner
end

function OwnerMngr.getOwner(part)
return ownedParts[part]
end

--more stuff

return OwnerMngr

.. and require it when you need it.

shouldn't function OwnerMngr.setOwner(part, owner) be
OwnerMngr:SetOwner(part,owner) ??

also can u link me to a guide about that? I'm confused on adding methods to tables like that.
Report Abuse
DiamondBladee is not online. DiamondBladee
Joined: 24 Feb 2013
Total Posts: 3527
12 Apr 2016 07:32 PM
@KAMI Thats if you have ONE server-side module; that gets into metatables and OOP (object oriented programming), which is waaay off topic but pretty useful.
Report Abuse
jode6543 is not online. jode6543
Joined: 16 Jun 2009
Total Posts: 5363
12 Apr 2016 07:44 PM
I don't know how much you already know about tables, so I'll first confirm that you know that the following two lines do the same thing (since it seems the latter syntax is never so much as mentioned in the wiki article on tables):

someTable["someValue"] = 5
someTable.someValue = 5

In Lua, functions are treated just the same as any other type of data; they can be assigned to variables, stuck into functions, passed as parameters to other functions, etc etc. With that in mind, the following code is also valid:

someTable.someValue = function()
return 5
end

.. or, to make it prettier, this code does the same thing:

function someTable.someValue()
return 5
end

It is not actually OwnerMngr.setOwner() that is unusual; it is OwnerMngr:setOwner(). Where'd that colon come from? In just the same way that we can make the function declaration above prettier, OwnerMngr:setOwner() is just a prettier way of saying OwnerMngr.setOwner(OwnerMngr). Passing the table that contains the function to the function itself is often useful. An example:

local Enemy = {}

function Enemy.attack(self, player)
-- do some stuff
self._ammo = self._ammo - 1
end

function Enemy.suicide(self)
self._health = 0
end

function Enemy.new()
local newEnemy = {}
newEnemy._ammo = 50
newEnemy._health = 100

--This could be done with metatables, but that's beyond the scope of this explanation
for k,v in pairs(Enemy) do
if k ~= "new" then
newEnemy[k] = v --reuse the functions
end
end

return newEnemy
end

local enemy = Enemy.new()
enemy:attack(aPlayer)
enemy:suicide()

However, OwnerMngr didn't require this type of functionality, so I didn't include it. That was a bit of a long-winded explanation, but I hope that answers your question.
PS. I should also note one more piece of syntax sugar:

function Enemy.attack(self, player) end
-- is the same as...
function Enemy:attack(player) end
Report Abuse
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
13 Apr 2016 09:14 PM
so when you:

someTable.someValue = function()
return 5
end

you're essentially giving the function the name of someValue's?

And you could call that function with - someTable.someValue()
Report Abuse
KAMIKAZEPOLO is not online. KAMIKAZEPOLO
Joined: 14 Mar 2012
Total Posts: 1049
13 Apr 2016 09:44 PM
One more question, that script you made with the enemy,

how would I use it?

Would I put that in a server-side script? I'm confused on how those functions are needed if it's just an internal script. I understand that it's an example, but if I were to create a bunch of enemy entities how would I have those all communicate?

Would I put them in a modulescript and have the scripts inside of the entities require that module to receive that table? Can you explain the applicable use?

Also thank you very much for that explanation, that was probably one of the best simply explained answers I've seen so far!
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