Map Database  •  FAQ  •  RSS  •  Login

Scripting hints

<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 30 Jun 2014, 05:50

Scripting hints

I created a wiki page with some hints for scripters based on mistakes/problems I saw in the Scripted Mission Competition:
https://code.google.com/p/castlesand/wi ... riptsHints

I wrote most of this ages ago and was planning to publish it after the competition results are released, but unfortunately the results have been massively delayed. Hopefully this page will help you improve your code. If you have any questions or comments just ask :)
<<

pawel95

Castle Guard Swordsman

Posts: 1912

Joined: 03 Oct 2008, 22:00

KaM Skill Level: Skilled

Location: "Pawel95" on Youtube.com

Post 30 Jun 2014, 06:30

Re: Scripting hints

Wow nice that you want to help scripters with your "guide". I personally like the last part that shows an extreme way of wasting performance :D
<<

Skypper

Knight

Posts: 436

Joined: 28 Jun 2013, 09:37

KaM Skill Level: Fair

Location: Dutch :D

Post 30 Jun 2014, 09:15

Re: Scripting hints

Looks good, I should have read this when I made Invasion.
Greets Skypper (Totally Insane)

- Beginning map maker -
<<

The Dark Lord

User avatar

King Karolus Servant

Posts: 2154

Joined: 29 Aug 2007, 22:00

KaM Skill Level: Veteran

Location: In his dark thunderstormy castle

Post 30 Jun 2014, 15:16

Re: Scripting hints

Pff, Warfare Scripted was perfect in every way. Don't need this!

Just kidding, seems like some neat tips I might want to try out in the future. :)
<<

Duke Valennius

User avatar

Militia

Posts: 44

Joined: 10 Jul 2013, 11:01

KaM Skill Level: Average

Post 01 Jul 2014, 10:37

Re: Scripting hints

Hints look good, however I really wouldn't advice to omit "begin...end"s to make code shorter. Imagine when someone decides to add another command like this:
  Code:
if stuff then do thing; do another thing; something;
Indentation looks legit, however it works different than it looks. If you use "begin..end"s that could not happen:

  Code:
if stuff then begin do thing; do another thing; end; something;
If "do another thing" does something that doesn't show up immediately (like incrementing some hidden counter) this can lead to some long debugging. Of course, if you have text editor with good and reliable auto-indendation, it should correct you. Maybe it is just my preference, but wasting one line for end is worth reducing error for me. I also think that it looks neater when there is lot of nested stuff and everything have "begin..end"s instead of mixed, but that's just me ;)
<<

Lewin

User avatar

KaM Remake Developer

Posts: 3822

Joined: 16 Sep 2007, 22:00

KaM Skill Level: Skilled

ICQ: 269127056

Website: http://lewin.hodgman.id.au

Yahoo Messenger: lewinlewinhodgman

Location: Australia

Post 02 Jul 2014, 07:38

Re: Scripting hints

Hints look good, however I really wouldn't advice to omit "begin...end"s to make code shorter.
These things are obviously a matter of taste. In Pascal most people put the "begin" on a separate line, instead of on the same line like this:
  Code:
if stuff then begin DoThing; DoAnotherThing; end; Something;
The above code already jumps out as wrong to me, because I can see two indented lines but no expected "begin" before the indentation. I would write it like this:
  Code:
if stuff then begin DoThing; DoAnotherThing; end; Something;
If you always write it with the begin and end on a separate lines then you don't make the mistake of omitting them because the code looks wrong without them (at least it does to me after having done that for years). Using an editor with syntax highlighting helps with that because the begin..end are bold, and you automatically start expecting to see them before/after every indentation. You'll find most Pascal/Delphi/Lazarus code looks like my example above with the begin on a new line and omitting begin..end if there's only one statement.

I find omitting the begin..end can make code a lot neater and readable (15 lines down to 8 in the hints wiki example).

But as I said, there is no right or wrong answer to coding standards like these, it's about personal preference and complying with the standards of your development team.

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 0 guests