Map Database  •  FAQ  •  RSS  •  Login

Dynamic Script Usage Questions

<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 21 May 2013, 08:43

Re: Dynamic Script Usage

We cannot expose States.CurrentPlayer because of the reasons explained by Lewin above.

However you probably can:

1. Spread the load across several ticks (HighCPUloadTextCreation((TickCount div 100) mod PlayerCount)), will do the processing each 10 sec for new player
2. Greatly optimize the HighCPUloadTextCreation (cache values, avoid "heavy" queries)
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 21 May 2013, 09:05

Re: Dynamic Script Usage

Caching is tricky, because of missing string-arrays. Storing them inside int-arrays stills needs to fetch those arrays, check for boundaries and then convert it to strings. So I'm not sure if the gain is worth the effort. I can't really test it either because I have a very strong CPU in my machine.

HighCPUloadTextCreation is already called inside a load balancer, so it updates only every 30 ticks. But still theres a factor of 8 where there only needs to be a factor of 1 of CPU load, because 7 times it's called just to throw away its output. And I've seen many weak CPUs out there, so it could still cause a lag every 3 seconds.

Another idea: would it be possible to overload SetOverlayText with a second api and a function pointer? So you could withdraw the exection of the function whenever you will withdraw the text display anyways. And still the CurrentPlayer is not public accessible. Does PascalScript allow function pointers?
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 21 May 2013, 09:14

Re: Dynamic Script Usage

Even if we could employ function pointers, we still have the issue of CurrentPlayer, because that function should run the same for all players, same as above.

Maybe you can post your HeavyLoadFunction and we could see why it takes so long and maybe there's a way to optimize it.
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 21 May 2013, 12:48

Re: Dynamic Script Usage

This function is too large for the forum, because it calls a few subfunctions, some loops over arrays and two case of-switches. The core of the function is a 'for i:=1 to 8 do'. That's not just some 100% or even 200% ballast that a full optimization may free. It's additional 700%.

But I see your point and understand why you don't want to make this variable public. So I'll work around that somehow and keep the outer for-loop.
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 21 May 2013, 13:32

Re: Dynamic Script Usage

First off you can skip AI players and defeated. Another consideration is that if it takes so much time to calculate maybe there's another way to fulfill the same need with different means.
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 21 May 2013, 13:57

Re: Dynamic Script Usage

If we go ahead with using markup for text then we can enable strings (and string arrays) in global variables so that might help.

You can do more load balancing than just calling HighCPUloadTextCreation every 30 ticks. Only update 1 player every 5 or 10 ticks, as Krom suggested. Regarding performance, it doesn't matter if your function only runs every 30 ticks or every single tick, if it takes too long to run it will still cause some lag. Lag every 3 seconds is almost as bad as continuous lag from the player's perspective. At 1x speed we need to do 1 tick per 100ms. So we get 100ms to do game logic updates and script OnTick, then leftover time is used for rendering. If we don't finish the game logic or script OnTick within 100ms then the next tick will be delayed, causing lag. So you should try to spread the load over multiple ticks, rather than just making it run less frequently.
<<

Siegfried

User avatar

Knight

Posts: 494

Joined: 24 Jul 2009, 22:00

Post 21 May 2013, 14:39

Re: Dynamic Script Usage

OK, now I understand what you mean. Wrap the text generation in another caller function that does distribute each player calculation. That's good. Thanks for that.

Anyways, I will get my hands on a very slow CPU tonight so I can check whether my fears are reasonable at all ;)

Another question: is it sufficient to check States.PlayerAllianceCheck(A towards B) to see if they are both in one team in multiplayer?
<<

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 21 May 2013, 15:40

Re: Dynamic Script Usage

Another question: is it sufficient to check States.PlayerAllianceCheck(A towards B) to see if they are both in one team in multiplayer?
Yes. The only time that:
States.PlayerAllianceCheck(A, B)
will not be the same as:
States.PlayerAllianceCheck(B, A)

is when you specifically define the alliances in the mission to be like that. This means that one player will attack the other, while the other will not attack back because they think they're allied. I've only seen this used once (in TPR), in a mission uploaded to my site where you had to run away from enemies. Your guy would not attack the enemy but the enemy would attack you. In multiplayer the teams selection in the lobby always overrides the .dat script anyway, unless it's coop.
<<

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 23 May 2013, 16:49

Re: Dynamic Script Usage

Hi

I want to show a message and i bence told my how, but when i started the game a bug appear. I have saved the file in the map TBT01 like TBT01.script and this is what i write in the file.

procedure OnTick;
begin
ifStates.GameTime = Something(10) then
Actions.ShowMsg(0, 'The village in the north is being attacked by an unknown army. Thou shalt defend it and defeat that army');
end;

This is the error that appear.

Warnings in script
[Error] (3:1): Unknown identifier `IfStates`

Could someone tell my what i do wrong?
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 23 May 2013, 17:25

Re: Dynamic Script Usage

You need to add a space between IF and States ;)
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
<<

Bence791

Knight

Posts: 618

Joined: 20 Jul 2012, 20:25

KaM Skill Level: Beginner

Location: Hungary

Post 23 May 2013, 17:38

Re: Dynamic Script Usage

Islar, I told you at least 3 times to do it ;)
The Kamper is always taking my colour!

<<

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 23 May 2013, 20:53

Re: Dynamic Script Usage

that space don't solved the problem. i have the same error. Could it something else?
<<

Siegfried

User avatar

Knight

Posts: 494

Joined: 24 Jul 2009, 22:00

Post 23 May 2013, 22:24

Re: Dynamic Script Usage

i have the same error
The space really solves this. Believe me.

The error messages says, that the interpreter does not know the word 'IfStates'. That's really not what you wanted to write. You want to have a check ('if') on States.GameTime.

So you have to write: "if States.GameTime ..." with the space between if and States.GameTime.
<<

Krom

User avatar

Knights Province Developer

Posts: 3281

Joined: 09 May 2006, 22:00

KaM Skill Level: Fair

Location: Russia

Post 24 May 2013, 04:52

Re: Dynamic Script Usage

@Islar: Now you would have a different error, show it to us! )
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
<<

Islar

Pikeman

Posts: 180

Joined: 22 Apr 2013, 20:18

KaM Skill Level: Average

Location: The Netherlands

Post 24 May 2013, 14:38

Re: Dynamic Script Usage

Finally

It works now. I think it came because when i changed it the wrong map still existed in the map when the new one was added to the map. I don't know how this came but when i look there was one file with TBT01 (the wrong one) and a file TBT01.script (the good one) and i couldn't open the wrong one but i could delete it.

Thanks for your help. :D

Return to “Dynamic Scripting”

Who is online

Users browsing this forum: No registered users and 3 guests