Page 1 of 1

I need help with dynamics scripting

PostPosted: 13 May 2014, 11:56
by Michalpl
How i can make a loop that will run the dynamic script every 1 min?
There is my code
begin
if States.UnitpositionX(10)then;
Actions.GiveAnimal(31,10,10);
end;

Re: I need help with dynamics scripting

PostPosted: 13 May 2014, 12:38
by Skypper
your code
  Code:
begin if States.UnitpositionX(10)then; Actions.GiveAnimal(31,10,10); end;
mycode
  Code:
Procedure onTick; begin if(states.GameTime mod 600 = 0) then begin if States.UnitpositionX(10) then begin Actions.GiveAnimal(31,10,10); end; end;
not sure if this works, didn't test it.
good luck

Re: I need help with dynamics scripting

PostPosted: 13 May 2014, 13:38
by Michalpl
I meaned the Repeat command not one time maybe lewin knows...

Re: I need help with dynamics scripting

PostPosted: 13 May 2014, 13:45
by Skypper
with this script your code well be execute every 60 secondes.

with states.gametime you get the play time of the game.
with "mod" you can calculate what the remainder of game time is, if that is 0, it is exactly 1 whole minute.
it can be the 1 minute but also the 56 minute.

I hope i explained it understandable :$

Re: I need help with dynamics scripting

PostPosted: 13 May 2014, 14:32
by Michalpl
Yea but its does'nt work

Re: I need help with dynamics scripting

PostPosted: 13 May 2014, 14:40
by Skypper
here is a map, with a working example.
it will spawn every minute a single serf

Re: I need help with dynamics scripting

PostPosted: 13 May 2014, 14:51
by Michalpl
Ty it works with serf and animals

Re: I need help with dynamics scripting

PostPosted: 14 May 2014, 01:33
by Lewin
How i can make a loop that will run the dynamic script every 1 min?
There is my code
begin
if States.UnitpositionX(10)then;
Actions.GiveAnimal(31,10,10);
end;
That code is not valid for a few reasons:
- You don't put a semicolon after "then", that ends the if-statement, so GiveAnimal will get executed every time (and the if-statement has no effect).
- "10" is not a valid parameter to UnitPositionX. You need to give it a unit ID which was given to you from a function like UnitAt.
- UnitPositionX returns a number. Your statement is like saying "if 5 then ...". "if 5" is meaningless and won't compile. You need to compare the number to something so you end up with a true/false statement. For example: "if States.UnitpositionX(SomeUnit) = 12 then" ("if 5 = 12" is valid since it is either true or false).