tisdag 9 mars 2010

Harddrive not detected in windows

Have you just bought a new harddrive, and it's not showing up under "My Computer"? Or have you borrowed / lent a harddrive from someone, plugged it in, and it's not showing up? The same thing happened to me, and this is how I got it working. This guide is for the old Windows XP, but should be similar for Vista and Windows 7. This guide also assumes that you have the correct jumper and cable settings.

This fix should work on any model, since this is a Windows problem, and not a problem with the harddrive ( you can breathe, your harddrive isn't broken! ). The problem is a conflict within Windows itself, and occurs when you map network devices to a letter ( like E:\, F:\, etc), or use daemon tools (such as in my case), or in other ways "use up" the "next" free letter. If you have two harddrives, and a CD-player, they might be mapped to C:, D:, and E:. If you have F: mapped, by mapping network devices, daemon tools, USB drives (mp3 player for instance), etc, and you have a new harddrive plugged in, Windows wants to give it the "next" letter, which in the case above would be F:\. If it's occupied there will be a conflict, and the new harddrive won't be shown.

First step:
First, check if you can see the new harddrive in BIOS. This guide assumes you can see it there.

Optional:
If you have the model number for your harddrive (I got mine from the website I ordered it from, I couldn't be arsed opening the computer up again and check for myself), you can check if Windows knows it's plugged in.

  • Start -> Control Panel
  • Add Hardware
  • Click Next

    It will scan for devices, and when it's done it'll ask if you have connected the device already.

  • Select "Yes, I have already connected the hardware"
  • Click "Next"

    You'll see a long list of devices. You might recognize some, you may not. It doesn't matter. Scroll down the list until you get to the harddrives. If you don't know the names of the harddrives, look at the icons, they look like square gray harddrives. If you only had one harddrive before, and you see two harddrives now, you know that Windows recognizes its presence. This guide assumes the harddrive is shown in the list.

    You can now close the guide, we only used it to make sure that Windows knows it's there.

    Second step:
  • RMB (Right Mouse Button) on "My Computer", select "Manage".
  • In the new window that appeared, choose "Disk Management" (subcategory of "Storage")

    Your right side of the window should be split in an upper and bottom part. The upper part shows the installed harddrives, C:\, and if you had another device, also something like D:\. In the bottom part of the window, you should see one more drive than is listed in the upper window. That extra drive is your new harddrive, and it's not shown in the upper window because it has no letter assigned to it. Identify your new drive (the one with the gray bar, or the one that has no letter in its name).

  • RMB (Right Mouse Button) on the bar of the drive
  • Choose "Change Drive Letter and Paths..."
  • Assign a letter to the drive, and you're done!

    If you can't assign a letter to the drive, it means you'll need to defragment the harddrive (most likely you had planned this anyway). So instead of choosing "Change Drive Letter and Paths...",

  • Choose "Format".

    And go on from there. If you managed to plug in an internal harddrive, you should know how to format a drive. =) And all you need to do if wait for the format to complete, and it'll pop up in "My Computer", like the rest of your harddrives.
  • torsdag 4 juni 2009

    Getting DSL: Setting up a full webserver (part 2)

    In order to have a linux-based server up and running, you need a checklist of items that you need. This guide is generic, which means it doesn't matter if you'll run a server or a desktop-type computer, it will work for both.

    1) A computer to install DSL on.
    2) A linux-distribution (aka dist) on a removable medium (f ex a CD, or a USB-drive)

    I will assume you already have the computer. I will also assume you'll burn a CD.

    Getting Damn Small Linux:
    You can download DSL here.
    You can find DSL's website for further information here.
    You can find a list of download sites on their download-page, located here.

    In order to get DSL, from their FTP, to a CD, do the following:
    1) Download DSL. Links are supplied mere centimeters above this sentence.
    2) Burn it onto a CD. Most likely you had a burning-program supplied when you bought your CD-burner. If you need help with installing a CD-burning program, I suggest you google for a guide. Most Linux dists are supplied in an .iso form, which means it's a one-file copy of a CD. Most CD-burning programs have an option to burn this image as it is, if you don't know how to do this, there are countless of guides about this. Try to google something in the lines of "burning iso with x", where x is the name of your CD-burning program.

    When you have the image on the CD, by which I hope you didn't burn the .iso-file as it is through Windows built-in burning feature (read: when looking what's in your CD all you see is a single .iso file = big no-no), you are ready to go. Simply put the CD into your server-to-be, and start it. When you get to the screen where you can input a command, type "install" (without quotes) and press enter.

    I suggest you partition your harddrive by selecting the 10th option at the following screen. This creates a 200Mb system-partition, where the system is installed, another 200Mb partition that acts as a swap (a dedicated partition for the Linux equivialent to the Windows "Virtual Memory"), and the third partition is where you can put all your stuff in. The nice part of Linux is that no matter how many partitions you have, the system will "behave" (as in, what you see) as if you only have one partition. No need to supply different paths for different partitions as in Windows, with the C:\programs, D:\setupfiles, or E:\mysql, they'll all be accecible without the initial X:.

    When you have partitioned your harddrive(s), by saving the settings in the partition-program and then exiting, you are returned to the previous list of options. This time, choose to do the hard drive install. During the install, you will be asked to use [g]rub or [l]ilo as bootloaders. From what I've gathered, Grub is the hands-down favourite, and is what I use myself. A bootloader is the nifty little program that displays a list of installed Operating Systems on the computer, and allows you to select what OS to load. It also allows you to use different type of "boot-codes" of the same OS, in case you want to load your Linux with different types of settings. One example can be if you want to get into the "Windows" and work on your programming, or if you simply want to boot the server as a server in CLI (Command Line Interface, like DOS for Windows). But this is extra features you don't have to know anything about in order to simply use Linux as a server.

    When the install is done, you'll be asked to supply a password for "root", and for "dsl". "root" is the Administrator-account in DSL, and "dsl" is the standard-account you normally boot into. Why not only use "root" you ask? It's for security. Most Windows users are spoiled with logging in with all privilegies to their computer, but if you're going to run a server, you actually won't need more privilegies than you need. And there's no need to risk a potential attack which can render your system useless if they can't render it useless.

    When it's all setup, you'll boot into the "Windows" (known as X-Windows), and voila, you're now a proud user of Damn Small Linux. If you're really into it, I suggest you take a look at their wiki. They list alot of answers and tutorials on most FAQ's, which is a very, very good spot to start at if you want to familiarize yourself with your new server-OS. The wiki can be found here.

    Feel free to comment or ask questions. I'll do my best to answer them all.

    fredag 29 maj 2009

    Benchmarking my DSL server with win ab.exe

    I decided it was time to find out where the bottlenecks on my server is. I have linux on my server, and WinXP on my workstation. Luckily, apache has a great tool for benchmarking on both versions, called ab (apache benchmark). On the windows version, it's a standalone file called ab.exe, which can be run from cmd.

    Server speccs:
  • 2.6Ghz intel Celeron
  • 256Mb RAM
  • 5400RPM hdd

    Server software:
  • Damn Small Linux 4.4.10 (Linux kernel 2.4.31)
  • Apache 2.2.9
  • PHP 5.2.6
  • MySQL 5.0.67

    Test 1:
    I decided to use a page with only phpinfo() on, in order to exagurate the amount of output the server would generate / page request. With other words, no DB-interaction.

    CLI vs. GUI:


    ab.exe -n 100 /phpinfo.php (CLI, rebooted)

    Time taken for tests: 12.078 seconds
    Complete requests: 100
    Requests per second: 8.28 [#/sec] (mean)
    Time per request: 120.781 [ms] (mean)
    Transfer rate: 476.58 [Kbytes/sec] received


    ab.exe -n 100 /phpinfo.php (GUI, also rebooted)

    Time taken for tests: 9.031 seconds
    Complete requests: 100
    Requests per second: 11.07 [#/sec] (mean)
    Time per request: 90.313 [ms] (mean)
    Transfer rate: 637.36 [Kbytes/sec] received


    I don't know if it's fluke or what, but +25% performance in (logged in) GUI compared to (at login promt) CLI really seems odd. I did the test trice with almost identical results.

    The rest of the tests are done in GUI, mainly for the ability to see the system load in realtime. Now, lets find the bottleneck.


    ab.exe -c 10 -n 1000 /phpinfo.php # Simulating 10 users, 1k requests.

    Time taken for tests: 86.063 seconds
    Complete requests: 1000
    Requests per second: 11.62 [#/sec] (mean)
    Time per request: 86.063 [ms] (mean, across all concurrent requests)
    Transfer rate: 668.83 [Kbytes/sec] received


    While monitoring the system load, CPU usage was around 10%, RAM usage was low, and network was nowhere near the cap of the bandwidth available. My guess is that it's the slow 5400 RPM harddrive that slows down the tests. But lets cramp up the numbers.


    ab.exe -c 50 -n 1000 /phpinfo.php # Simulating 50 users, 1k requests.

    Time taken for tests: 143.531 seconds
    Complete requests: 1000
    Requests per second: 6.97 [#/sec] (mean)
    Time per request: 143.531 [ms] (mean, across all concurrent requests)
    Transfer rate: 401.03 [Kbytes/sec] received


    CPU at 13-16%, RAM usage went up about 10Mb's, and network activity was still low. With a higher accesstime, my initial assumption of the slow harddrive seems correct, with more simultaneous tasks, it can't keep it up. I can continue to up the concurrent users, but we'll just see a higher Time per request, and lower Requests per second. I'm glad so far, however. Before I started testing I assumed the 256Mb RAM would be a problem. The 2.6Ghz celeron was abit of a wild card for me. While still very fast for a single-core CPU, celeron can't compete with any other type of CPU with the same frequency, especially at multi-tasking.

    When it's time, I'll benchmark the database performance. But for now, I'm happy with the results.
  • onsdag 27 maj 2009

    Setting up a full webserver using DSL 4.4.10 and LAMP/XAMPP (pt. 1, intro)

    This entire entry is me talking about everything and nothing. For the tutorial see part 2.

    Guide index, part:
    1 = This. Random thoughts and suggestions on road-maps.
    2 = Getting DSL, installing it.
    3 = Setting up your webserver on DSL, XAMPP + autostart.
    3.1 = Installing Apache + autostart (no XAMPP)
    3.2 = Installing PHP5 + autostart (no XAMPP)
    3.3 = Installing MySQL + autostart (no XAMPP)
    3.4 = Installing a FTP-server + autostart (no XAMPP)
    4 = Benchmarking the server
    5 = Setting up a DNS + auto-update. (if you have a dynamic IP).
    6 = Adding more server-support to your server: crons.
    7 = Tutorial on crons, and how to run php-scripts with it.

    ---
    With the lack of tutorials of how to download, install, and setup a linux-based webserver for DSL (Damn Small Linux), I decided to write down the steps I took to make mine, along with sharing my guidelines as to how, why and what. The why's are generally covered in this article. This guide is written to "100%" Windows users, who at least knows something worth knowing, not counting how to save a Word-document and how to start iExplorer.

    I'm a Windows user by heart. By heart, I mean I grew up with it. And by grew up with it, I mean I really can't stand the new versions anymore, especially true now with Vista. While I did feel the same with WinXP when it came out, the major reason I didn't like it was because it was bigger than Win2k, and there was new commands to learn. I still miss winipcfg. Don't get me wrong, WinXP (SP2) in its original form is a good OS, and has surprisingly low system requirements. It's just that I don't understand the point in the rediculous system requirements of the new OS'es that is way beyond any computer with a few years on the neck.
    Most people know of, have played, or are currently playing World of Warcraft. Assuming a gaming-system has 2Gb RAM, I'd prefer any day of the week to play WoW on WinXP with ~2GB RAM available, compared to the ~1Gb if playing on Vista. Even more so if the system has less than 2Gb RAM, say ~1.5Gb (3x512 or 1024+512), or still stuck with a single-core CPU.

    Every single year there are more "old" computers, and that pile will never cease to buildup, it will become bigger and bigger for every year. I don't understand why Microsoft makes new OS'es that require so much of a computers hardware, making sure older computers can't run them, and then stop supporting the OS'es those computers was preinstalled with, run with for so many years, and above all made the user addicted to. There's two ways to survive this. Or, actually three.

    First one, the most common one to survive as a Microsoft-addicted computer-user is to buy a bigger, meaner machine, toss the old one, and continue to use the new Microsoft OS, until they release a new OS, and stop supporting the old one.
    The second way, which I'm guessing is at least 99,99% of the users left, are the ones who tries to convert to some form of Linux-dist, most likely any that resembles Windows as much as possible for an easy transition. I'm very glad there are many Linux-dists that has this option, not only makes it ex-Windows-supporters' lifes easier, it pulls more people into the Linux world. However, Linux still has way less to offer gaming-wise. Which leads us to the next resort.
    Thirdly, in case you don't buy a new machine, and you don't convert to Linux, you decide to do something rather... unorthodox; compile your own Windows version. This is done by simply stripping the junk you don't want (outlook express, wordpad, a thousand drivers for hardware you don't have, etc), adding the stuff you need and want (such as security-updates and tools you use daily), and replacing the stuff you'll update anyway, such as DirectX, .NET Framework, etc. You then compile it all to a nice bootable install-CD, and voila, you have the perfect gift to yourself; the OS you are addicted to, tailored perfectly to your needs.

    ---

    Lets have a general talk about software. If you're used to Windows, and want to run a webserver, chances are you've tried to run one in Windows. I'm also guessing you've heard of how good Linux is as a server OS. The three examples above are more than just a random ramble, it helps you to identify yourself as a computer-user. It helps you to answer questions further down the road, if you know what type of computer-personality you have;
    Do you take what's handed to you (type1),
    weigh all your options, learn as much as you can, finding out how green the grass is on both sides of the road (type2),
    or do you stay with what you know and make the best of it (type3).

    Are you happy with the type of user you are? Regardless, you'll have to make a choice if you want to stick with it, or change to a new category, or make a blend. It won't change the questions presented to you, simply the answers you give back.

    ---

    Now, lets talk hardware. Even if you have a lean, mean, fighting leet-machine as a server with 4x4x4Ghz CPU's and 20Gb of DDR3 RAM, you still have to ask yourself;
    1) Do I want to spend (read: waste) resources on something I don't need?
    2) Do I want to bloat my server, or do I want it to run as fast as possible?

    If you're not into all of that micro-management / resource-optimizing crap, and just want to try or learn how to run a server in Linux, I recommend Fedora. During the installation you can choose what type of "packages" you want, such as Office stuff, Development stuff, or Server stuff. It also has a very Windows-like GUI. While this guide-series is not aimed toward your group, it can still act as a general guide, but it will assume you know more about Linux than the targeted group, since the directions aren't made for Fedora, but for DSL (4.4.10).

    If you on the other hand do give a crap, or simply are left with no choice since you have an old laptop or 486 (or whatever), read on. This guide is for you. This guide (read: I) assume you
    1) Have a limited amount of resources available on your server computer,
    2) Give a crap about resourcemanagement,
    3) Hate bloat.

    Regardless, the end-result is the same: pack everything you need into a server, and nothing more, or as little as possible more.

    Some more rant. There's no need to have a OS taking several Gbs worth of space, eating 1Gb of RAM for just idle activity. Those resources could (and should!) be used to serve your clients. Why get a server computer capable of running Vista as a server OS when you can
    1) settle for a cheaper / older computer, and run a less hardware-intense OS,
    2) run a less hardware-intense OS and open up more resources for your server?

    I think I've made my view on the matter clear. Feel free to comment or ask questions.

    lördag 16 maj 2009

    How to create a simple RPG fight engine using php

    Now that I'm working on finetuning my fight/raiding engine, I felt I could take a break and write a blogentry about the process of creating one. I decided to share my first version of what started as a turn-based fighting engine between two characters, and later evolved into a real-time fighting engine between 6 or more (read: large-scale war between hundreds or thousands of "soldiers"). I recommend new developers to start with a very simple version of whatever type of engine you're after, and incrementally put new stuff in. Start simple. Then add something. Then add another element. Add another attack, or RNG. Then some more stuff. Then gather the stats from a database, instead of having them predefined inside the script. Voila, you now have a scaling and dynamic engine, so long as your players/users can edit those figures somehow (such as health, damage reduction via armors, magics, or what have you).

    Lets have a look at the mighty 60 rows of code. Lets start with defining the stats for our two fighters.


    $player1 = array("Name" => "Good-Guy", "Health" => 100, "Damage_min" => 2, "Damage_max" => 4, "Hit_chance" => 80, "Critical_chance" => 5);

    $player2 = array("Name" => "Bad-Person", "Health" => 80, "Damage_min" => 3, "Damage_max" => 5, "Hit_chance" => 90, "Critical_chance" => 7);


    As you can see, one has lower health, but instead have a higher base damage, chance of actually hitting the enemy, and a higher chance of hitting a vulnerable spot (critical chance). Keep in mind this is a simple engine, which is a base to continue the development of your own engine.

    In order to find out who wins, we need to make sure the script continues simulating the fight until one of the competitors are dead. So, we create a loop, which is as follows:


    while ($player1['Health'] AND $player2['Health'] >= 1){


    This isn't excactly rocket science. This row simply states that "as long as player1 health and player2 health are both at 1hp or more, do this:"

    Since this is a turn-based fight, Player1 attacks first. After that Player2 attacks. Then Player1 gets a shot again. And then Player2 again. This will continue until one of them are dead.


    #Player 1 attacks:
    echo $player1['Name'] ." attacks ". $player2['Name'] ." for ";

    # Did he succeed in hitting the enemy?
    $hit_chance = rand(1, 100);
    if ($hit_chance <= $player1['Hit_chance']) {

    # Calculate the damage:
    $hit = rand($player1['Damage_min'], $player1['Damage_max']);

    # Did he succeed in making a critical hit?
    $crit_chance = rand(1, 100);
    if ($crit_chance <= $player1['Critical_chance']) $hit *= 2;

    # Reduce the amount of health the opposing player has left:
    $player2['Health'] -= $hit;

    echo $hit ." damage. ". $player2['Name'] ." has ". $player2['Health'] ." health left.
    ";
    }
    else {
    echo "0 damage (miss!). ". $player2['Name'] ." still has ". $player2['Health'] ." health left.
    ";
    }
    if ($player2['Health'] <= 0) break;


    You'll have to excuse the lack of indentation, it doesn't show for some reason. Lets go through this segment, piece by piece. This helps to understand the theory behind it. First off we need to find out wether or not Player1 can land the hit on Player2. There's numerous of ways of doing this, I chose a percentage-based system. We rand 1-100 to find a number, and compare it to the players chance of hitting his enemy, which in this case is 80%. As long as the rand is 1-80, he hits. If the rand is 81-100 (read: 20% of the cases), he misses his attack.

    If he succeeded in hitting his opponent, our next step is to find out how much he hits for. This is done by randing his minimum and maximum damage output. We can then calculate if he scored a critical hit in the same fashion we found out if he landed his blow, by randing 1-100, and comparing it to his chance to score a critical hit, and if so, we alter the damage he does by a crit-multiplier. I chose x2 damage because of the simplicity.

    Regardless of Player1 scoring a critical hit or just landing a normal hit, we need to reduce the health of Player2, along with reporting it.
    The else-part is there if Player1 misses his attack. If he misses his attack, there is no need to calculate how much damage he does, or if he crits or not. It will still do no damage. So we report it. We don't need to alter Player2's health in this case, since he didn't get hit. The last row, with the if-part, is there simply to make sure that Player2 is still alive to make his attack. If his health is 0 or lower, he can't make another attack. It's only logical.

    Player2's turn to attack. It's the exact same code, but where it previously said Player1 it now says Player2, and where it said Player2, it now says Player1.


    #Player 2 attacks:
    echo $player2['Name'] ." attacks ". $player1['Name'] ." for ";

    # Did he succeed in hitting the enemy?
    $hit_chance = rand(1, 100);
    if ($hit_chance <= $player2['Hit_chance']) {

    # Calculate the damage:
    $hit = rand($player2['Damage_min'], $player2['Damage_max']);

    # Did he succeed in making a critical hit?
    $crit_chance = rand(1, 100);
    if ($crit_chance <= $player2['Critical_chance']) $hit *= 2;

    # Reduce the amount of health the opposing player has left:
    $player1['Health'] -= $hit;

    echo $hit ." damage. ". $player1['Name'] ." has ". $player1['Health'] ." health left.
    ";
    }
    else {

    echo "0 damage (miss!). ". $player1['Name'] ." still has ". $player1['Health'] ." health left.
    ";
    }
    if ($player1['Health'] <= 0) break;
    }


    There is small addition to this part though, which is the curly bracket on the last row, below the last if-part. That one closes the while-loop that we started in the second code-block.

    We can add one more piece for closure, which simply will state who won. If you want, you can add statistics, logging misses, crits, and average hit damage inside the loop, and then output it here:


    # Someone has 0 or less health left.
    if ($player1['Health'] > $player2['Health']) echo "
    The winner is ". $player1['Name'] ."!";
    else echo "
    The winner is ". $player2['Name'] ."!";


    If you have questions or comments, feel free to make yourself heard below.

    onsdag 29 april 2009

    What is game balance, really? Thoughts from a developers PoV.

    A few words before we start:
    I really enjoy creating a serious online-game. Especially the fact that getting a dedicated team is hard at best, and going indie (solo) requires even more dedication, and is even harder, since time will be more of an issue. This really seperates the serious developers who loves what they're doing, whom goes under the "Made by gamers, for gamers"-motto, and the developers interested in a potential money-gain without realizing what it truly requires to create a well done and loved game, which isn't always equal to a cash-camel, -cow, or -piñata.

    In order to make a successful online game, you need balance between elements, and giving the game a depth. From an RPG PoV, classes has to be balanced, they need to scale "equally", and things like items, armors, mobs, bosses, even inventory of vendors has to have at least some degree of balance, if you want to give your gamers a serious impression. To some degree even such things as the players surroundings / scenery has to be properly balanced. One does not start playing a level 1 character in a game starting in the dragons lair killing rats, working their way to the rats lair, killing dragons. Balance and depth are keys.

    But how do I achieve balance and depth?
    In order to create a balanced game, I've had to do alot of sketching, alot of diagrams, and alot of number crunching. How and when should things scale? At what intervalls should the scaling be verified (read: synced)? What should scale? I can write it on paper, but how do I make the process automated? Where is the start and end of the scaling (level 1->X? Some games "start" at level 10)? Should there be a cap, if so, where, and on what: stats, avoidances, hit/crit, money, or things such as xp-gain or even onlinetime? If you haven't gotten the picture on how to create balance in your game yet, let me continue.

    In my sketch-books, containing hundreds of pages of notes, propositions and examples, I've an example of a working balanced system, at least in theory. In order to implement it, I've done way more than I anticipated.

    Adding 15 classes, all with different roles and dynamics, starting with gear in ~10 slots, 6 races, and 2 sexes, and keep them all BALANCED, with starting stats, starting gear, and what I call a "scaling-table", which is like a road-map the class in question uses when it gains a level for their automatic and/or manually distributed statgains. I've had to do alot of work. Starting to get the picture on what balance is? No? Let us continue then.

    Working through all the already mentioned, I've also had to actually create both class specific prefabricated items, and a automated item creation system, since lets face it, we don't want our NPC's to have the same gear all the way to the level-cap, and we do want some variety in the gear provied. 2,4 million combinations of gear per item-level, which is hidden levels for the items to determine their strength, obviously, and to make sure that the gear used is actually intended and balanced for the level of the NPC. We wouldn't want a mid-level player running around with the most powerful weapon in the game. Item-level is a way for the game to measure the strength of any given item.

    And for all previously mentioned elements to be balanced, I've had to create mobs and bosses with a difficulty rating that resembles the quality of the items which the player gains from killing the said mobs. Yeah. And how is that done, really? Is it balanced when a mob goes down quickly (Hack n' slash-genre warning), or should a mob actually provide a challenge? When is it too challenging? What should the droprate be? Should items be somehow bound to NPC's or the player, or should players be allowed to put any item up on the market for other players to buy? How would that affect the economy? Should items on the marked be available for players on the other continent? I can keep going with more vital and not-so vital questions. But the point is this;

    What is balance?
    Balance is truly in the eye of the beholder. The question is, should the game be balanced around the developers view of what is considered balance, or should he put himself in front of the screen of one of his players? Any gamer knows the answer to this question. Any gamer gone developer should know the answer to this question. But people who develop without actually playing, is like designing a moonbase for NASA without actually knowing what it'll be like living on the moon, along with what is appreciated from its users and what is not. Any serious developer does a decent amount of research. You're probably reading this article for that very reason. Heck, I've even read up on real-world ores, metalls, leathers, cloths and different kinds of processing techniques, just to find inspirations to the items, and that is just a small part of the entire game. So, I ask you, have you gotten the picture of how to create balance now?

    The one and only way to achieve balance, in plain english:

    If you've read through the article, you should already, on some level, already know the answer to this. The answer is planning. You can't create a balanced system on the fly, especially if it's big and complex. Even big-budget companies with a huge amount of developers spend months planning their several-years-project MMO's. I suggest getting a pen which feels good to grip and hold, and a notebook, which you carry around wherever you go. Whenever you get an idea, you write it down. Whenever you have time to kill, start sketching on ideas. Whenever *anything*, get it into your notebook. This is described by Stephen King in his book "On Writing", which is a book about writing books. In it he recommends anyone serious about writing to always carry a book with him/her, and read whenever an opportunity to do so arises, wherever he or she might be, even if it is "socially questionable", such as restaurants or in the bathroom. And it's actually not a bad idea. Carry a notebook and a pen wherever you go. When you wait for someone, you take it out. Whenever you're waiting for the train, you sketch in it. When the train has arrived and you've climbed aboard, you keep writing in it. When you're driving your car and can't write, I suggest listening to audio books. It doesn't have to be game-oriented. Anything that can act as an inspiration is a good source. Harry Potter, Sun Tzu's Art of War, and other well known books are good sources of insipration regardless of what type of game you're developing. They'll help you add depth to your game.

    It's not about making something fun and turning it into work. It's about endulging yourself with your passion wherever you are.

    måndag 27 april 2009

    Creating a random name generator with PHP






    While working on my auto-generated entry-level NPC's for my onlinegame, I noticed I wasn't really happy with the names that was generated. And since I spent time to make it sex-independent (males and females get seperate names), I decided to write a short article of how to create a random name generator using PHP. This guide is fantasy/rpg-based, but the principle can be applied to real names or what-have-you.

    There are many ways to do it, this is simply one of them. First off you'll need to decide if you want the names to be compiled by two or more parts, or if you simply want to get a random name from a list of names. I will show how to create names compiled by three parts, which will be the prefix, infix, and suffix (beginning, middle, and end). The scripts can however be modified to use more or less parts to create the random names.

    The reason behind me using three parts is because 1) it allows for a broader spectrum of possible names, and 2) gives me the option to use more combinations of masculine and feminine derivatives, both in the prefix and the traditional suffix. If you're interested in doing a good name-generator, I suggest you read up on derivatives.

    You can either decide to use arrays which contains the names, use a database, or textfiles. I find the use of a database overkill, and the use of arrays can get messy with a bad overview if you have many parts and many combinations. But for a small range of combinations and alternatives, arrays might be an easier option, and the code-example can easily be modified to use arrays instead of including the files in the first step.

    Now, on to the code. We'll show the feminine version.


    # Add the parts to arrays
    $prefix = file("includes/1_female.txt");
    $infix = file("includes/2.txt");
    $suffix = file("includes/3_female.txt");

    # Randomize them
    shuffle($prefix);
    shuffle($infix);
    shuffle($suffix);

    # Pick a (randomized) value
    $prefix = rtrim($prefix[0]);
    $infix = rtrim($infix[0]);
    $suffix = rtrim($suffix[0]);

    $name = "" .$prefix ."". $infix ."". $suffix ."";
    #Also works, but are considered "ugly":
    # $name = "$prefix$infix$suffix";



    *First part adds the contents of the files to variables as arrays, which means first row has the 0-key, second row has the 1-key, etc.
    *Next we'll need to randomize the content. There are several ways of doing this, I personally prefer shuffle(), since it makes things look more tidy. You could also count the lines of the file to a variable to use as the key with rand(0,sizeof($var)-1), and then use $prefix[$var] at the third step to get a random line from the file, though I personally think it looks ugly. Nevertheless, it's an option.
    *Third part is to pick out a random entry. Since we used shuffle(), we can use any valid key to get a random value, since we won't know the order of the array unless we peek inside it. First entry is always a good option, so we'll use the first key (0).
    *Last part is to simply put the pieces together. I decided to give an extra option of how to do this, since both do the same thing, and the massive usage of quotationmarks can be abit disctracting for new programmers.

    A very simple example of how the text-files are composed (suffix overlapping the prefix) using 2 parts to compose the names. Might be worth mentioning that when using infixes and suffixes, clever usage of blank lines works, and adds an extra dimension to the names, making some names to be shorter. But if you'd use the type of list below I'll guarantee that your names will look butt-ugly.


    The result can be viewed on top. It's hardly meeting any fantasy-standards, and some names might be abit of a tongue twister, but should at least serve as an example of what the end result would look like. Both sexes uses the same infix, but I use different prefixes and suffixes for the masculine and feminine names. See the first part of the code-example and you can probably figure out what needs editing to add masculine derivatives.