Map Cloning

by PopLava
[Share] [Zip]
To download this demo for your Linux/Mac installation, enter this on your command line:

DreamDownload byond://PopLava.MapCloning##version=1

Emulator users, in the BYOND pager go to File | Open Location and enter this URL:

byond://PopLava.MapCloning##version=1

99 downloads
Version 1.1
Date added: Feb 13 2012
Last updated: Feb 20 2012
0 fans
Map Cloning
Cloning maps with SwapMaps made easy [More]
This example shows how easy it is to clone maps with the SwapMaps library. You can dynamically generate maps from templates, randomize them, delete them, and teleport between them.

2/20/2012 - v1.1
- Minor tweaks to clean up source code per feedback.

Advertisement

Comments

Urias: (Feb 20 2012, 12:28 pm)
PopLava wrote:
Perhaps you could elaborate on my big mistake?

I apologize. It wasn't a big mistake, but a lot of DM programmers might find it a bit redundant, especially since a lot of them aren't used to the exposure of other languages.

I find that these prefixes enable me to fly through the code via the scroll bar to locate groups of things a lot faster than not having them. I also utilize this prefixing as a poor mans way of type-safety. It makes it obvious what context I'm currently in at all times (without scrolling). All in all, I make far fewer mistakes when moving code around because I never lose sight of the intended context.

That's fine. I didn't say your prefixing style was wrong, everyone has their own style of formatting their code.

PopLava: (Feb 20 2012, 11:26 am)
Yut Put wrote:
awkward prefixing and naming is counter intuitive if you're looking for other people to read and comprehend your code.

It's not so awkward that people can't easily figure it out. If I were to go and grab a sampling of function names from random examples across this site, I'm fairly confident that my function names are far better than most (prefix or no).

Regardless, it's a style preference and therefore should not be on the table for debate unless I requested it.
PopLava: (Feb 20 2012, 11:23 am)
Urias wrote:
Forum_account wrote:
1. There's an awful lot of code for something so simple. The curly braces certainly don't help with that.

I'm gonna have to agree here. You should most certainly remove the curly braces. If you think you're emphasizing code-readability, especially in a language like DM(which is 'weakly-typed'), you have made a big mistake.

Perhaps you could elaborate on my big mistake?

5. The Mob_- and Proc_- prefixes are wildly unncessary.

A style of prefixing variables/functions are completely up to a programmer; he/she pursue a style that they're comfortable with. Though the Proc_- prefix is nonsensical in this case because you are, after all, creating a procedure.

I find that these prefixes enable me to fly through the code via the scroll bar to locate groups of things a lot faster than not having them. I also utilize this prefixing as a poor mans way of type-safety. It makes it obvious what context I'm currently in at all times (without scrolling). All in all, I make far fewer mistakes when moving code around because I never lose sight of the intended context.


6. Some of your variable names are overly elaborate, like "iUserProvidedZLevel". For a local variable in a three line proc a one-letter name would have been sufficient. There's also "listOfTurfsInView" in the Proc_ResetToGrass proc which is overly elaborate and not even used =)

http://en.wikipedia.org/wiki/Naming_convention_(programming)

Sure... I have an elaborate variable in there which probably was converted from a global var or something along those lines. Although, I'm not afraid to provide meaningful variable names because it bakes my original intention into the code.

I can freely move blocks of code around without losing sight of a variables original meaning and I reduce my chances for wrongly using it.

When I come back to the code a couple months or years later, reading my code provides you with a self-documented history of intention.
PopLava: (Feb 20 2012, 10:57 am)
Forum_account wrote:
There's nothing wrong with the style that you've used but it's quite different from what most DM programmers are used to seeing. Most people will be thrown off by the code and won't be able to make sense of it.

Pure speculation.

While a lot of my comments seem superficial, the details that are important for educational demos like this are often extremely superficial. You can turn a good demo into a bad one (or vice versa) by changing variable names and whitespace. It's not all about function.

Or... you could turn a good example into a better one.

You also went to great lengths for some superficial details (variable names, proc name prefixes, curly braces, semicolons, etc.), so you clearly value how code looks and not just how it functions.

Not great lengths and it's mostly just requirements of other languages and applied standards through code reviews. It's far easier to apply the similarities than to constantly make mistakes across my environments. With that said, I believe my layout choices make the code far easier to read when compared with the BYOND preferred syntax.

PopLava wrote:
Your also mistaken about the variable usage.

Here's the code:

>   Proc_ResetToGrass(var/listOfTurfsInView)
> {
> for (var/turf/t in view(10))
> {
> t.icon_state = "grass";
> }
> }
>


The listOfTurfsInView argument isn't used at all. It's also a misleading name since the list doesn't really have to be a list of turfs in view. The proc could reset the icon_state for any list of turfs.

My local copy utilizes the variable so I must have uploaded a different build somehow. Either way, thanks for pointing this out.
Yut Put: (Feb 20 2012, 10:05 am)
awkward prefixing and naming is counter intuitive if you're looking for other people to read and comprehend your code.