TG Sync 12/15/17
s s
This commit is contained in:
@@ -312,7 +312,7 @@ var/list/bag_of_items = list(sword, apple, coinpouch, sword, sword)
|
||||
var/obj/item/sword/best_sword
|
||||
for(var/obj/item/sword/S in bag_of_items)
|
||||
if(!best_sword || S.damage > best_sword.damage)
|
||||
best_sword = S
|
||||
best_sword = S
|
||||
```
|
||||
The above is a simple proc for checking all swords in a container and returning the one with the highest damage, and it uses DM's standard syntax for a for-loop by specifying a type in the variable of the for's header that DM interprets as a type to filter by. It performs this filter using ```istype()``` (or some internal-magic similar to ```istype()``` - this is BYOND, after all). This is fine in its current state for ```bag_of_items```, but if ```bag_of_items``` contained ONLY swords, or only SUBTYPES of swords, then the above is inefficient. For example:
|
||||
```DM
|
||||
@@ -320,7 +320,7 @@ var/list/bag_of_swords = list(sword, sword, sword, sword)
|
||||
var/obj/item/sword/best_sword
|
||||
for(var/obj/item/sword/S in bag_of_swords)
|
||||
if(!best_sword || S.damage > best_sword.damage)
|
||||
best_sword = S
|
||||
best_sword = S
|
||||
```
|
||||
specifies a type for DM to filter by.
|
||||
|
||||
@@ -332,7 +332,7 @@ var/obj/item/sword/best_sword
|
||||
for(var/s in bag_of_swords)
|
||||
var/obj/item/sword/S = s
|
||||
if(!best_sword || S.damage > best_sword.damage)
|
||||
best_sword = S
|
||||
best_sword = S
|
||||
```
|
||||
Of course, if the list contains data of a mixed type then the above optimisation is DANGEROUS, as it will blindly typecast all data in the list as the specified type, even if it isn't really that type, causing runtime errors.
|
||||
|
||||
@@ -355,9 +355,9 @@ DM has a var keyword, called global. This var keyword is for vars inside of type
|
||||
|
||||
```DM
|
||||
mob
|
||||
var
|
||||
global
|
||||
thing = TRUE
|
||||
var
|
||||
global
|
||||
thing = TRUE
|
||||
```
|
||||
This does NOT mean that you can access it everywhere like a global var. Instead, it means that that var will only exist once for all instances of its type, in this case that var will only exist once for all mobs - it's shared across everything in its type. (Much more like the keyword `static` in other languages like PHP/C++/C#/Java)
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
[Changelogs]: # (Please make a changelog if you're adding, removing or changing content that'll affect players. This includes, but is not limited to, new features, sprites, sounds; balance changes; map edits and important fixes. An example changelog has been provided below for you to edit or remove. If you need help, read https://github.com/tgstation/tgstation/wiki/Changelogs)
|
||||
|
||||
[Changelogs]: # (Your PR should contain a detailed changelog of notable changes, titled and categorized appropriately. This includes, new features, sprites, sounds, balance changes, admin tools, map edits, removals, big refactors, config changes, hosting changes and important fixes. An example changelog has been provided below for you to edit. If you need additional help, read https://github.com/tgstation/tgstation/wiki/Changelogs)
|
||||
|
||||
:cl: optional name here
|
||||
add: Added new things
|
||||
@@ -8,13 +7,16 @@ del: Removed old things
|
||||
tweak: tweaked a few things
|
||||
balance: rebalanced something
|
||||
fix: fixed a few things
|
||||
wip: added a few works in progress
|
||||
soundadd: added a new sound thingy
|
||||
sounddel: removed an old sound thingy
|
||||
imageadd: added some icons and images
|
||||
imagedel: deleted some icons and images
|
||||
spellcheck: fixed a few typos
|
||||
experiment: added an experimental thingy
|
||||
code: changed some code
|
||||
refactor: refactored some code
|
||||
config: changed some config setting
|
||||
admin: messed with admin stuff
|
||||
server: something server ops should know
|
||||
/:cl:
|
||||
|
||||
[why]: # (Please add a short description [two lines down] of why you think these changes would benefit the game. If you can't justify it in words, it might not be worth adding.)
|
||||
|
||||
Reference in New Issue
Block a user