RiftWorks
Найти
Персональное меню
Вы не представились системе
user-interface-preferences
Персональные инструменты
Обсуждение
Вклад
Создать учётную запись
Войти
Параметры
notifications
Редактирование:
Binary flags
(раздел)
associated-pages
Статья
Обсуждение
Просмотры
Читать
Править
Править код
История
Внимание:
Вы не вошли в систему. Ваш IP-адрес будет общедоступен, если вы запишете какие-либо изменения. Если вы
войдёте
или
создадите учётную запись
, её имя будет использоваться вместо IP-адреса, наряду с другими преимуществами.
Анти-спам проверка.
Не
заполняйте это!
== 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.
Описание изменений:
Обратите внимание, что все изменения в RiftWorks рассматриваются как выпущенные на условиях лицензии Creative Commons Attribution-NonCommercial-ShareAlike (см.
RiftWorks:Авторские права
). Если вы не хотите, чтобы ваши тексты свободно распространялись и редактировались любым желающим, не помещайте их сюда.
Вы также подтверждаете, что являетесь автором вносимых дополнений или скопировали их из источника в общественном достоянии или под совместимой лицензией.
Не размещайте без разрешения материалы, защищённые авторским правом!
Отменить
Справка по редактированию
(в новом окне)