Map Database  •  FAQ  •  RSS  •  Login

Dynamic Script Usage Questions

<<

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 13 Apr 2013, 03:58

Re: Dynamic Script Usage

Every tick the game does the following:
1. Add 1 to game time (what you get from States.GameTime)
2. Update game assets (units, houses, etc.)
3. Run the code you put in OnTick.

So the reason it only happens once is because the condition States.GameTime = 1000 only occurs once. After that GameTime is 1001, 1002, etc. If you want it to happen every 1000 ticks (so 1000, 2000, etc.) you need to make the condition States.GameTime mod 1000 = 0. The tutorial I made explains how this works and what mod does.

Try to remember you are writing code for the game to execute step by step, just like if it was VB or C++ or Delphi.
<<

Ben

User avatar

Former Site Admin

Posts: 3814

Joined: 08 Jan 2009, 23:00

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

Post 13 Apr 2013, 04:30

Re: Dynamic Script Usage

Don't tell people that I coded in VB! It's embarrassing :P

Anyway, sorry that I missed the tutorial. I'll read the whole thing over and not just skim it :)

I'm not very good at coding. I've always had a hard time comprehending certain parts of it (like these parameters or the "functions" in C#). Yet, programming is one of my favorite things to do...so thank you for your patience!
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 13 Apr 2013, 05:11

Re: Dynamic Script Usage

I coded in VB at school too, don't worry ;)

The KaM Remake should be a fairly good language to learn to program on, it's not too complicated and it's well documented, plus you probably have a bigger motivation to learn it :P
<<

Siegfried

User avatar

Knight

Posts: 494

Joined: 24 Jul 2009, 22:00

Post 13 Apr 2013, 08:00

Re: Dynamic Script Usage

Is there a good language reference?

For example something as good as php.net/manual or selfhtml?
It's just so annoying to search for all that little functions that are so easy but you don't know the exact name; like IntToStr ... ;)
<<

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 13 Apr 2013, 08:22

Re: Dynamic Script Usage

Is there a good language reference?

For example something as good as php.net/manual or selfhtml?
It's just so annoying to search for all that little functions that are so easy but you don't know the exact name; like IntToStr ... ;)
The script compiler we use (PascalScript) only has limited functionality, so not all of the functions in Delphi or Free Pascal are available. However most of the basic ones are, and the basic data types (Integer, string, set, static/dynamic arrays, etc.) are the same. Delphi Basics is a really good reference site:
http://www.delphibasics.co.uk/
For example this page has IntToStr and other similar ones:
http://www.delphibasics.co.uk/ByFunctio ... in=Numbers

Just keep in mind that Delphi has far more features than this language so a lot of the stuff there won't work ;)

I've added a link to Delphi Basics on our wiki pages, thanks for the suggestion.
<<

Siegfried

User avatar

Knight

Posts: 494

Joined: 24 Jul 2009, 22:00

Post 13 Apr 2013, 16:33

WTF?

  Code:
var names: array[1..5] of string;
results in "Unsupported global variable type 22: "

Are arrays of strings not supported? Is this a bug?
<<

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 13 Apr 2013, 16:46

Re: WTF?

  Code:
var names: array[1..5] of string;
results in "Unsupported global variable type 22: "

Are arrays of strings not supported? Is this a bug?
You can't have global variable arrays of strings at the moment, since global variables need to be saved by the game (so it restores the same after loading it) and we didn't write a handler to save strings yet.

Why do you want to store strings in a global variable anyway? We couldn't really forsee any use for that which couldn't work just as well by storing an integer.
<<

Siegfried

User avatar

Knight

Posts: 494

Joined: 24 Jul 2009, 22:00

Post 13 Apr 2013, 17:15

Re: Dynamic Script Usage

You can leave this out, I will use a monstrous function instead ;)
I was curious why I can have a global array of int but not of string because both are fundamental types.
<<

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 13 Apr 2013, 17:28

Re: Dynamic Script Usage

You can leave this out, I will use a monstrous function instead ;)
I was curious why I can have a global array of int but not of string because both are fundamental types.
Well we could implement it if you have a practical use for it. We only added saving handlers for certain types, so some aren't supported in global variables such as 64 bit integers and doubles (64 bit floats). It's possible to add stuff like this, but it didn't seem necessary to us.
<<

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 13 Apr 2013, 17:30

Re: Dynamic Script Usage

It's working now, thanks. :)
Meanwhile I'm trying to use Actions.SetOverlayText to display a message for all players, e.g. "The Dark Lord has defeated the first attack wave!" I got this message working, but then I want to erase it again. How can I do this? I'm trying to overwrite the text with an empty string, but I want it to be delayed (lets say after 5 seconds).

Currently I have added this code:
  Code:
const DELAY = 50; var DelayedErase: Boolean; DelayedTime: Integer; procedure HideOverlayMsg; begin if (DelayedErase = true) and (DelayedTime = (States.GameTime + DELAY)) then begin Actions.SetOverlayText(0, States.Text(29)); Actions.SetOverlayText(1, States.Text(29)); Actions.SetOverlayText(2, States.Text(29)); Actions.SetOverlayText(3, States.Text(29)); DelayedErase := false; end; end;
DelayedErase becomes true after defeating the first attack wave.
It's a very dirty way of hiding the text, and it doesn't even work. :P I'm guessing my use of DelayedTime is wrong? HELP!!! :mrgreen:
<<

Siegfried

User avatar

Knight

Posts: 494

Joined: 24 Jul 2009, 22:00

Post 13 Apr 2013, 17:47

Re: Dynamic Script Usage

Well we could implement it if you have a practical use for it.
I had a practical use in mind, but I can solve this with a function, so you don't have to do the work because of me.

For me it would be WAY BETTER if I could use classes, but I guess that this is already beyond the border of pure scripting.
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 13 Apr 2013, 17:53

Re: Dynamic Script Usage

Well we could implement it if you have a practical use for it.
I had a practical use in mind, but I can solve this with a function, so you don't have to do the work because of me.
If you post that idea, maybe that could convince us this is a needed feature :)
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
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 13 Apr 2013, 17:56

Re: Dynamic Script Usage

For me it would be WAY BETTER if I could use classes, but I guess that this is already beyond the border of pure scripting.
Maybe that could be implemented time after. Main reason we don't add much features support is serialization. Every variable needs to be saved and load on gamesave and gameload, doing that for classes is more sophisticated than plain variables )
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
<<

Siegfried

User avatar

Knight

Posts: 494

Joined: 24 Jul 2009, 22:00

Post 13 Apr 2013, 18:09

Re: Dynamic Script Usage

If you post that idea, maybe that could convince us this is a needed feature :)
I wanted to implement a series of goals and each goal gets its own abbreviated name. Because it's abbreviated, there is no need to translate it and therefore no need to put it into the libx.

But it's really not needed. I was curious why it did not work, nothing more :)

@classes
I understand that. Well, after all everything is possible with procedural programming.

But speaking of feature support:
is there a way to prevent enemy (but not allied) troops from entering a specific area? Will this be possible?
<<

Krom

User avatar

Knights Province Developer

Posts: 3280

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 13 Apr 2013, 18:29

Re: Dynamic Script Usage

You can add abbrevs into Eng libx and keep them empty in other locales. Then upon display empty strings will be replaced with fallback (Eng) locale text. No need to have strings in script for that :)

I doubt we can add "AvoidArea" function, but who knows, maybe some day .. )
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

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 6 guests