Page 8 of 26
Re: Dynamic Script Usage
PostPosted: 21 May 2013, 08:43
by Krom
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)
Re: Dynamic Script Usage
PostPosted: 21 May 2013, 09:05
by Siegfried
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?
Re: Dynamic Script Usage
PostPosted: 21 May 2013, 09:14
by Krom
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.
Re: Dynamic Script Usage
PostPosted: 21 May 2013, 12:48
by Siegfried
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.
Re: Dynamic Script Usage
PostPosted: 21 May 2013, 13:32
by Krom
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.
Re: Dynamic Script Usage
PostPosted: 21 May 2013, 13:57
by Lewin
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.
Re: Dynamic Script Usage
PostPosted: 21 May 2013, 14:39
by Siegfried
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?
Re: Dynamic Script Usage
PostPosted: 21 May 2013, 15:40
by Lewin
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.
Re: Dynamic Script Usage
PostPosted: 23 May 2013, 16:49
by Islar
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?
Re: Dynamic Script Usage
PostPosted: 23 May 2013, 17:25
by Krom
You need to add a space between IF and States

Re: Dynamic Script Usage
PostPosted: 23 May 2013, 17:38
by Bence791
Islar, I told you at least 3 times to do it

Re: Dynamic Script Usage
PostPosted: 23 May 2013, 20:53
by Islar
that space don't solved the problem. i have the same error. Could it something else?
Re: Dynamic Script Usage
PostPosted: 23 May 2013, 22:24
by Siegfried
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.
Re: Dynamic Script Usage
PostPosted: 24 May 2013, 04:52
by Krom
@Islar: Now you would have a different error, show it to us! )
Re: Dynamic Script Usage
PostPosted: 24 May 2013, 14:38
by Islar
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.
