ok so as Lyqyd stated you will need to use numbers, not what you have used there, Lua doens't understand or have a data type for binary numbers. So 00100000 it actually just sees as 100000, so in order to use that number you would actually need to use 32 (which is decimal) or 0x20 (which is hex). Both of these formats is supported by Lua.
Now as for making levels only modify their own info first you need to understand binary AND and OR, so I'll detail now
AND
1 AND 1 = 1
1 AND 0 = 0
0 AND 1 = 0
0 AND 0 = 0
OR
1 OR 1 = 1
1 OR 0 = 1
0 OR 1 = 1
0 OR 0 = 0
Ok so now that you can see what happens with these we can start to understand how to do the dungeon checking and modifying.
Now you have made it nice and easy for checking and setting since each dungeon uses a new bit.
Ok so checking existence of a dungeon is as easy as
local function hasAccess( code, require ) --# code is their current access level ... require is the level required to access
return bit.band( code, require ) == require
end
Now the way this works is because of the rules I showed you above, if the bit is on in both the code and the require then it stays on in the result. However if either one is missing a bit when it should be there then it will be off in the result, and obviously if they're both off it will also stay off. So the only way for this statement to return true is for the result from the bit AND to be the code needed. small example:
0000 0001 &
0000 0001 =
0000 0001 (match)
0000 0011 &
0000 0001 =
0000 0001 (match)
0000 0011 &
0000 0100 =
0000 0000 (failed)
0000 0100 &
0000 0010 =
0000 0000 (failed)
So as you can see it will not succeed unless that specific bit is on, now in contrast if you use OR this would be the result
0000 0001 |
0000 0001 =
0000 0001 (match)
0000 0011 |
0000 0001 =
0000 0011 (failed)
0000 0011 |
0000 0100 =
0000 0111 (failed)
0000 0100 |
0000 0010 =
0000 0110 (failed)
So as you can see with OR it will
only let the person through if that bit is the
only bit on.
Why did I show you both ways? Well your description of your problem and use case can be interpreted different ways, and as I'm unsure of which way you wanted I figured best to just show you both.
Now to add a new dungeon to the persons access is easy too, you can do the following
local function add( code, new ) --# code is the current access level ... new is the new dungeon to be added
return bit.bor(code, new)
end
Now this will only add the dungeon if required, if it is already in there, then nothing is changed
To remove a dungeon is also as easy as
local function remove( code, del ) --# code is the existing access level ... del is the dungeon to be removed
return bit.band(code, bit.bnot(del))
end
Ok so now you see how you can add and remove, I'm going to show you the easy way to add the dungeon code for adding and removing so you don't have to remember how the numbers.
--# example of added dungeon 6 to the current access
--# as a binary number dungeon 6 is 0010 0000
local access = 0
--# in hex (requires knowing the hex value for 32
access = add(access, 0x20)
--# as a decimal number (this can start to get harder to calculate the further along you get)
access = add(access, 32)
--# the easiest way 2^(n-1), so in this case is 2^(6-1) = 32
access = add(access, 2^(6-1))
Using the last method it means that you can easily write loops to check existence and such
local access = 0x20
for i = 1, 16 do --# for dungeons 1 -> 16
if hasAccess(access, 2^(i-1)) then
print( "You have access to dungeon: "..i )
end
end
So with all the above information you should be able to build your programs that you require that give the players access to the dungeons.
I hope all this has helped, if you have any questions just ask :)/>
— BIT