see an example below:
/datum/race/proc/get_magic_types()
return null
/datum/race/human/get_magic_types()
alias/approved_magic_types = list("fire", "ice")
return approved_magic_types
/datum/race/elf/get_magic_types()
// #define MAGIC_TYPES list("earth", "plant")
// return MAGIC_TYPES
alias/approved_magic_types = list("earth", "plant")
return approved_magic_types
another sample:
/datum/proc/check_available()
if( proc_a() && proc_b() && src.this_okay && proc_c() && proc_d() || proc_all_pass() )
return 1
return 0
// long if condition. ugly.
#define CAN_CAST_MAGIC (proc_a() && proc_b() && src.this_okay && proc_c() && proc_d() || proc_all_pass())
/datum/proc/check_available_with_macro()
if(CAN_CAST_MAGIC)
return 1
return 0
// it reads better because you know the context of the if condition, but macro? cringe
/datum/proc/check_available_with_alias()
alias/can_cast_magic = proc_a() && proc_b() && src.this_okay && proc_c() && proc_d() || proc_all_pass()
return can_cast_magic
// this reads perfectly sane.
I'd like to elaborate the last proc.
/datum/proc/check_available_with_alias()
alias/can_cast_magic = proc_a() && proc_b() && src.this_okay && proc_c() && proc_d() || proc_all_pass()
return can_cast_magic
this is actually the same below:
/datum/proc/check_available_with_alias()
#define can_cast_magic (proc_a() && proc_b() && src.this_okay && proc_c() && proc_d() || proc_all_pass())
return can_cast_magic
#undef can_cast_magic
and that becomes:
/datum/proc/check_available_with_alias()
return (proc_a() && proc_b() && src.this_okay && proc_c() && proc_d() || proc_all_pass())
What we can get:
- this works like a semi-macro, so it doesn't occupy variable memory
- you can have a same name in multiple area, not doing #undef and #def every time.
- you can give a name to a condition instead of contextless verbose in the if condition
Why do we want this?:
/datum/proc/check_available()
return proc_a() && proc_b() && src.this_okay && proc_c() && proc_d() || proc_all_pass()
This is contextless, so we might want to do this:
/datum/proc/check_available()
var/can_cast_magic = proc_a() && proc_b() && src.this_okay && proc_c() && proc_d() || proc_all_pass()
return can_cast_magic
but this takes a variable. we might want to return the value directly without saving it.
< Alias behavior >
For example, when `/mob/alias/check_client = { if(src.client) {return src.client;} else {return global.fake_client;} }` is defined, this `check_client` is accessible from all mob procs. (but I am not sure this is a good idea... proc alias seems fine to me, but not this)
- you can undef alias by doing "alias/alias_name = null"
- assigning values to an alias should be always done with "alias/alias_name = value" syntax, not omitting "alias/" part, because it is not a real variable.
- alias does not exist in runtime because it's deconstructed to what's stated.