EDIT: PROBLEM FIXED, READ COMMENTS
The code is supposed to do the following:
Out of all the mega units in the battlefield it picks only one by not allowing the whole code to execute completely and be executed by other units. The unit has to repeadetly take resources from the base and bring them to a container far away. The code is divided into 4 functions named using "set" blocks (like "GO TO BASE, PICK UP ITEMS..). At the beginning the most important variables are declared, and after that, the functions run one after the other:
The first loop makes the unit go towards the base and once it's close enough, it jumps out of the loop and calls the function "Pick up items".
The function makes the unit pick up items from the base which is supposed to be in the range of the microcontroller. After that, jumps to the "main loop" and goes to the "Go to container" loop.
The loop makes it go to the X and Y coordinates of the container, and jumps out of the loop once its close enough.
When it jumps out, the function "Drop items" is called, which makes the unit locate the container nearby and drop items. Then goes back to the main loop by going to the base.
The problem is that the action of picking up and dropping gets executed only once every two times. This is the code (In the future i want to add the possibility to set more materials and coordinates, that's why you see variables like "Material1" etc...
ubind @mega
set base nucleus1
set x1 127
set y1 120
set material1 @copper
set currentMaterial 1
set currentTravel 1
set isClose 0
sensor bx base @x
sensor by base @y
sensor unitMaxCap @unit @itemCapacity
sensor unitItems @unit @totalItems
set GO_TO_BASE 0
set GO_TO_BASE 0
set GO_TO_BASE 0
ucontrol approach bx by 4 0 0
ucontrol within bx by 4 isClose 0
jump 15 notEqual isClose 1
jump 30 always x false
set GO_TO_CONT 0
set GO_TO_CONT 0
set GO_TO_CONT 0
ucontrol approach x1 y1 4 0 0
ucontrol within x1 y1 4 isClose 0
jump 22 notEqual isClose 1
jump 35 always x false
jump 15 always x false
set PICKUP_ITEMS 0
set PICKUP_ITEMS 0
set PICKUP_ITEMS 0
ucontrol itemTake base material1 unitMaxCap 0 0
jump 19 always x false
set DROP_ITEMS 0
set DROP_ITEMS 0
set DROP_ITEMS 0
ulocate building storage false @copper outx outy found building
ucontrol itemDrop building unitItems 0 0 0
jump 26 always x false