Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Search Today's Posts Mark Forums Read

Thread Tools Search this Thread Display Modes
Old 12-01-2006, 02:04 AM
jake13jake jake13jake is offline
Former Classic Staff
jake13jake's Avatar
Join Date: Dec 2002
Location: Northwest Vermont
Posts: 1,452
jake13jake will become famous soon enough
Why Quick and Dirty Code Doesn't Cut It

In the world of computer programming, employers are trying to improve programmer time efficiency. This means the time spent on creating a program is less and, in turn, sacrifices program efficiency.

Three reasons why not to write quick code:
1. Lack Expandibility
2. Lack Reusability
3. Lack Readability

When you're writing a script, always break it down into independent tasks. I'll use movement for my example.

What do you need to move?
1. direction, speed.
2. possible detection of wall. (believe me, there are other ways than onwall)
3. distance to wall.
4. changing player coordinates.
You could make independent functions for all of these, and using variable and function names that make sense, it will be much easier to understand when someone else is looking at it, or you're reviewing it.

*Always keep in mind what you can reuse in other scripts, or what variables you can manipulate through other scripts.

You could make player.dir and movement direction independent. By doing this, you could make it so you can move a player so that the player is always facing a target, or that the player is walking sideways, backwards etc.

You could make wall detection detect by tiletypes, or even with exceptions to tiletypes of a certain tile. You could make it so that you can easily change the tiletypes or exceptions. When you detect the wall you can return the distance from the player to the wall.

You could make the player's base dynamic in wall detection. Making offsetx/y, width, and height variables.

You could reuse all of this with a clientside NPC, and if you have the energy, make a version of it that would work for serverside movement.

*Always plan for the future.
Add functionality that you're going to use in the future.

For instance, the reason to detect tiletypes in a movement script is so that you can define horses not to go over chairs, etc. Or if you're feeling like playing a prank on the server, you can make it so nobody can sit down on a chair, or so that you can only walk on wall tiles.

All of this work is NOT a waste of time. It will save you hours of slaving over your keyboard just to write many other scripts that could have been done with three lines of code had you not made things so sloppy.
Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +2. The time now is 06:16 PM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.