CRPL problem [solved]

Started by Annonymus, November 19, 2013, 07:04:55 AM

Previous topic - Next topic

Annonymus

I want to create a unit which moves along a predefined way and removes digitalisgrowth where it passes, this is the script:

$speed:2
$waypoint1x:0
$waypoint1y:30
$waypoint2x:30
$waypoint2y:30
$waypoint3x:30
$waypoint3y:0
$waypoint4x:10
$waypoint4y:0
$waypoint5x:10
$waypoint5y:10
$waypoint6x:0
$waypoint6y:10
$keycoordx:5
$keycoordy:5
#initializes the tower
once
1 ->nomoved
1 ->nomoved2
1 ->nomoved3
1 ->nomoved4
1 ->nomoved5
1 ->nomoved6
endonce
#checks if the condition is met (in this case if the shieldkey is collected)
if (<-keycoordx <-keycoordy GetUnitAt GetUnitType "SHIELDKEY" neq)
#if it never moved before, it moves to the first waypoint
if (<-nomoved)
<-waypoint1x <-waypoint1y <-speed QueueMove
endif
#if it arrives at the 1. waypoint it sets the variables to the conditions needed to do the 2. step
If (CurrentX <-waypoint1x eq CurrentY <-waypoint1y eq and) 1 ->moved1 0 ->nomoved endif
#if it's at the 1. waypoint it moves to the 2. waypoint
if (<-moved1 <-nomoved2 and)
<-waypoint2x <-waypoint2y <-speed QueueMove
#if it's at the 2. waypoint it sets the vonditions needed for the 3. step
If (CurrentX <-waypoint2x eq CurrentY <-waypoint2y eq and) 1 ->moved2 0 ->nomoved2 endif
endif
#repeat the same thing for step 3 - 6
if (<-moved2 <-nomoved3 and)
<-waypoint3x <-waypoint3y <-speed QueueMove
If (CurrentX <-waypoint3x eq CurrentY <-waypoint3y eq and) 1 ->moved3 0 ->nomoved3 endif
endif
if (<-moved3 <-nomoved4 and)
<-waypoint4x <-waypoint4y <-speed QueueMove
If (CurrentX <-waypoint4x eq CurrentY <-waypoint4y eq and) 1 ->moved4 0 ->nomoved4 endif
endif
if (<-moved4 <-nomoved5 and)
<-waypoint5x <-waypoint5y <-speed QueueMove
If (CurrentX <-waypoint5x eq CurrentY <-waypoint5y eq and) 1 ->moved5 0 ->nomoved5 endif
endif
if (<-moved5 <-nomoved6 and)
<-waypoint6x <-waypoint6y <-speed QueueMove
If (CurrentX <-waypoint6x eq CurrentY <-waypoint6y eq and) 1 ->moved6 0 ->nomoved6 endif
endif
endif
#sets digitalisgrowth and digitalis to 0
CurrentCoords 0 SetDigitalisGrowth
CurrentCoords 0 SetDigitalis

after much trying and failing i got it to work but after every step (at every waypoint) it waits a bit, after the next step it waits ca. 2x the time it waited before, at the 3. its 2x the time of the 2. and so on, at the 5. waypoint it waits ca. a minute which is very annoying but i can't find the reason.  :(
If a topic started by me is in the wrong place feel free to move it at anytime.

eduran

#1
Your script keeps executing QueueMove while the core is still moving and only stops once it reaches the target. At that point all orders are still in the queue and get executed one at a time. Nothing happens - because the core is already at the destination - but it still takes one frame per queued move order. Just queue up all of the moves when you want the core to start moving and make sure moves get queued only once:

# Move.crpl
# Created on: 11/19/2013 1:38:46 PM
# ------------------------------------------
$speed:2
$waypoint1x:0
$waypoint1y:30
$waypoint2x:30
$waypoint2y:30
$waypoint3x:30
$waypoint3y:0
$waypoint4x:10
$waypoint4y:0
$waypoint5x:10
$waypoint5y:10
$waypoint6x:0
$waypoint6y:10
$numberOfWaypoints:6
$keycoordx:5
$keycoordy:5

once
FALSE ->start
FALSE ->stop
endonce
# check if the key is collected
if(GetUnitType(GetUnitAt(<-keycoordx <-keycoordy)) neq("SHIELDKEY") and(not(<-start)))
TRUE ->start
endif
# queue up all waypoints; 'stop' makes sure this only happens once
if(<-start and(not(<-stop)))
# the loop is a fancy way of executing QueueMove several times
# could be replaced by six seperate QueueMove commands
do(<-numberOfWaypoints add(1) 1)
QueueMove(<-!("waypoint" concat(i) concat("x")) <-!("waypoint" concat(i) concat("y")) <-speed)
loop
TRUE ->stop
endif

Annonymus

If a topic started by me is in the wrong place feel free to move it at anytime.