Map Database  •  FAQ  •  RSS  •  Login

Dynamic Script Usage Questions

<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 10 Apr 2013, 13:46

Dynamic Script Usage Questions

By request of Krom, I am starting this topic where a discussion left off in a different topic.

(continued from here)
So, just to make sure I am understanding the syntax of the code correctly, to unlock the sawmill, I'd use this code:
  Code:
OnHouseBuilt(9 //woodcutter's) Begin HouseUnlock(0 //Sawmill) End;
Last edited by Ben on 10 Apr 2013, 13:49, edited 1 time in total.
I used to spam this forum so much...
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 10 Apr 2013, 13:49

Re: Dynamic Script Usage

Not exactly right. The actual code will be more like this:
  Code:
OnMissionStart; begin for I := 0 to 28 do HouseBlock(I); HouseAllow(_store); HouseAllow(_school); end; OnHouseBuilt(aHouse: Integer); begin if aHouse = _quarry then HouseAllow(9); if aHouse = 9 then HouseAllow(0); end;
where _something are IDs that I dont remember :D
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 10 Apr 2013, 13:51

Re: Dynamic Script Usage

With the exceptions of the undercores, is this the exact code? I.e., I'd actually write "for I :=0 to 28 do"? I don't understand this line.
I used to spam this forum so much...
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 10 Apr 2013, 13:59

Re: Dynamic Script Usage

I didn't checked that code in-game, just wrote from the top of my head.

"for I :=0 to 28 do" means that we do something (HouseBlock(I);) for every I in range from 0 to 28 - these are all houses in KaM.
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
<<

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 10 Apr 2013, 14:25

Re: Dynamic Script Usage

Please refer to our Wiki when writing dynamic scripts:
http://code.google.com/p/castlesand/wik ... ptsDynamic

Krom's examples are not using exact syntax and he forgot about multiple players. The script should be more like this:
  Code:
procedure OnMissionStart; var I, P: Integer; begin for P := 0 to <number of locations on your map minus 1> do if States.PlayerEnabled(P) then begin for I := 0 to 28 do States.HouseAllow(P, I, False); States.HouseAllow(P, _store, True); States.HouseAllow(P, _school, True); end; end; procedure OnHouseBuilt(aHouse: Integer); begin if States.HouseType(aHouse) = _school then HouseAllow(States.HouseOwner(aHouse), _inn, True); if States.HouseType(aHouse) = _quarry then HouseAllow(States.HouseOwner(aHouse), _woodcutter, True); end;
Replace _something with the house number (same as you use in .dat scripts).
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 10 Apr 2013, 16:06

Re: Dynamic Script Usage

Please refer to our Wiki when writing dynamic scripts:
http://code.google.com/p/castlesand/wik ... ptsDynamic
The Wiki's tutorials are not very helpful (for a novice programmer such as myself); which is why I wanted to ask here on the forum.
Krom's examples are not using exact syntax and he forgot about multiple players. The script should be more like this:
  Code:
OnMissionStart; var I, P; begin for P := 0 to <number of locations on your map minus 1> do if States.PlayerEnabled(P) then begin for I := 0 to 28 do States.HouseAllow(P, I, False); States.HouseAllow(P, _store, True); States.HouseAllow(P, _school, True); end; end; OnHouseBuilt(aHouse: Integer); begin if States.HouseType(aHouse) = _school then HouseAllow(States.HouseOwner(aHouse), _inn, True); if States.HouseType(aHouse) = _quarry then HouseAllow(States.HouseOwner(aHouse), _woodcutter, True); end;
Replace _something with the house number (same as you use in .dat scripts).
In
  Code:
I := 0 to 28
What exactly does that colon mean? This may sound like a silly question, but understanding the meaning of syntax helps me grasp it better.

Also,
  Code:
States.HouseAllow(P, I, False)
This looks like it is blocking all houses for all players, right? I is the variable that represents all houses, and P is the variable that represents all players (These are variables, right? Or are they slightly different in some way?). What if I just wanted to enable it for one player? What code do I use?

A side question: Is this language case sensitive?
I used to spam this forum so much...
<<

Gradius

Farmer

Posts: 20

Joined: 04 Jan 2013, 16:23

KaM Skill Level: Fair

Post 10 Apr 2013, 16:54

Re: Dynamic Script Usage

Sorry for the 'OT but wanted to ask if the action will be implemented in order to eliminate the road, so that when you have two stores, it's not that the servants vadino to take stuff elsewhere .. also always asked for the reason of the two deposits, which if you could take off the street, and the servants are created from the school vault A, these will work only for their "fence" of the road, so not going to vault B in the case they serve the servants to bring such food at the inn ..
Sorry if it is not clear for google translate
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 10 Apr 2013, 17:12

Re: Dynamic Script Usage

I understand that Gradius is using a translator, so he may not understand the layout of the forum very well, so can an administrator kindly move his post to the appropriate thread (maybe the ideas topic) and delete this post of mine? This scripting is very important to me. Thank you.
I used to spam this forum so much...
<<

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 10 Apr 2013, 18:07

Re: Dynamic Script Usage

In
  Code:
I := 0 to 28
What exactly does that colon mean? This may sound like a silly question, but understanding the meaning of syntax helps me grasp it better.

Also,
  Code:
States.HouseAllow(P, I, False)
This looks like it is blocking all houses for all players, right? I is the variable that represents all houses, and P is the variable that represents all players (These are variables, right? Or are they slightly different in some way?). What if I just wanted to enable it for one player? What code do I use?

A side question: Is this language case sensitive?
In Pascal:
A:=B means "set A to equal B"
A = B means "is A equal to B (true or false)"

Also, read this:
http://en.wikipedia.org/wiki/For_loop

For loops are a basic programming structure that allow you to do something over and over again. In this case, the for loop runs 29 times. First it runs with I=0, then I=1, then.... I=28. Hence "I:=0 to 28". Yes I and P are integer variables, you can see that they're declared within the scope of that function. So yeah, within the scope of that for loop I does many "every house" if you want to think of it that way, but sometimes the order you do things in matters so you need to keep in mind how it really works underneth. The purpose of that code is to set every house to "not allowed" meaning it shows with a "?" in the build menu, but it can still be allowed later if you build the house that unlocks it (so you could change it to only unallow the school and inn if you wanted, but this way makes sure it overrides any changes made in the .dat script).

The language is not case sensitive, but it's much less readable if you don't use camel case.
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 10 Apr 2013, 19:53

Re: Dynamic Script Usage

Okay, thanks. That's all for now.

I'm used to not capitalizing the first word in my variables, but I like the way you are doing it here (in fact, I think that I was using your method before my professor told me to try not capitalizing the first word) so I think I will train myself to do it your way.
I used to spam this forum so much...
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 11 Apr 2013, 06:09

Re: Dynamic Script Usage

First word capitalization is just a matter of taste and coding style accepted in certain circles (uni, work, team, programming language, etc). Also some languages are case sensitive (e.g. JavaScript) and some are not (Delphi, Pascal). Since KaM dynamic scripting is done in Pascal you can use any case that suits you.
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 11 Apr 2013, 12:40

Re: Dynamic Script Usage

The list of codes in the wiki, are they actual code taken from the Remake's source? That is, for example, is OnHouseBuilt the code you use to detect when a house is done?
The reason I'm wondering is because I'm curious if the list of codes for dynamic script are limited to the ones in the wiki.
I used to spam this forum so much...
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 11 Apr 2013, 13:14

Re: Dynamic Script Usage

We have a layer between scripts and main code so that we can change either side without affecting the other. The list of scripts is limited to those we expose through that layer.
Knights Province at: http://www.knightsprovince.com
KaM Remake at: http://www.kamremake.com
Original MBWR/WR2/AFC/FVR tools at: http://krom.reveur.de
<<

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 11 Apr 2013, 13:15

Re: Dynamic Script Usage

The list of codes in the wiki, are they actual code taken from the Remake's source? That is, for example, is OnHouseBuilt the code you use to detect when a house is done?
Not exactly... We wrote the Remake from the ground up. There's no level lower that can provide a "OnHouseBuilt" event for us to use, we wrote everything there is about houses ourselves. In fact, the game code is that lower level. When a house is built we check "does the mission script have an OnHouseBuilt event?" If yes, we run that event.
The reason I'm wondering is because I'm curious if the list of codes for dynamic script are limited to the ones in the wiki.
No, the ones on the Wiki are the only ones available. We have to implement every command listed there, by providing a layer between the script and the game code (which is very raw, easy to break, always changing and not as simple to use as we want scripts to be). That layer is this file:
http://code.google.com/p/castlesand/sou ... ingESA.pas

When you script, you only get access to those two classes, States and Actions. If we let you access the game structures directly scripting would be as difficult as writing the game itself is, and you'd have to change your script as we change/improve/rewrite the game code. So we made States and Actions and that's all which gets exposed to the script.
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

Location: California - Pacific Time (UTC -8/-7 Summer Time)

Post 12 Apr 2013, 03:06

Re: Dynamic Script Usage

The game isn't recognizing "HouseAllow" Is it a bug or have I mistyped something?
  Code:
procedure OnMissionStart; var I, P: Integer; begin for P := 0 to 5 do if States.PlayerEnabled(P) then begin for I := 0 to 28 do States.HouseAllow(P, I, False); States.HouseAllow(P, 11, True); States.HouseAllow(P, 13, True); end; end;
It's not understanding line 8. I'm, assuming lines 10 and 11 won't work either.
I used to spam this forum so much...

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 9 guests