Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
/VM/station wiki
Search
Search
Log in
Personal tools
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Binary flags
(section)
Page
Discussion
English
Read
Edit
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
View history
General
What links here
Related changes
Special pages
Page information
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== The idea behind bitflags == Back to our disabilities. Let's assume we want to implement 4 disabilities. The only bit of information we need is whether a mob has a disability or not. We could do: var/disability1 = 0 var/disability2 = 0 var/disability3 = 0 var/disability4 = 0 The problem however is that it would be very hard to add a 5th disability later on, as well as it requiring four integers, where we only really need 4 bits of information. (0b0000) So we'll make a flag variable, you define them the same way as you define any numeric variable: var/disabilities = 0 Remember, I mentioned all of these numeric variables are represented with bits, so we have just created a variable that actually has the value of 0b000000000000'''0000'''. We will use the four bits furthest to the right (bold) to determine our four disabilities. But first we will need to define numbers for them. The numbers we will use have to be unique bits, so we'll use: 0b0001 = poor eyesight 0b0010 = poor hearing 0b0100 = broken leg 0b1000 = broken arm This will give us enough information to tell if someone has a disability or not, since if someone has the value of 0b0000, we know he doesn't have any disability, if he has 0b0001, we know he has poor eyesight, if he has 0b0101, we know he has both a broken leg and poor eyesight. For easier use we will define these values as preprocessor constants. How exactly these differ from program constants is not too important for now. You however define them by opening setup.dm (code folder) and adding lines that look like this: #DEFINE DISABILITY_EYE 1 #DEFINE DISABILITY_EAR 2 #DEFINE DISABILITY_LEG 4 #DEFINE DISABILITY_ARM 8 Most often it is best to put these in setup.dm, because they are only defined from the spot where they're defined in the file on, and setup.dm is the first file loaded. Why did we pick 1,2,4,8? Because the binary value of 0b0001 is 1 (decimal); 0b0010 is 2 (decimal); 0b0100 is 4 (decimal) and 0b1000 is 8 (decimal). Okay, so now we have the constants defined that will allow us to manage disabilities and we have a variable to store the information about disabilities.
Summary:
Please note that all contributions to /VM/station wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
/VM/station wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Toggle limited content width