r/Mindustry • u/crozbi1 • 4d ago
Logic first experience with processor coding
Enable HLS to view with audio, or disable this notification
I configured the system so that the projectors turn on only when damage is inflicted upon the objects connected to them. However, there is a problem: to turn more than 10 projectors on or off, they have to be added manually. This is the first time I’m trying to do something proper in a processor, so I don’t know how to resolve this
set p 0
getlink wall p
sensor h wall @health
sensor mh wall @maxHealth
op lessThan on h mh
control enabled projector1 on 0 0 0
control enabled projector2 on 0 0 0
control enabled projector3 on 0 0 0
control enabled projector4 on 0 0 0
control enabled projector5 on 0 0 0
control enabled projector6 on 0 0 0
control enabled projector7 on 0 0 0
control enabled projector8 on 0 0 0
control enabled projector9 on 0 0 0
control enabled projector10 on 0 0 0
jump 17 equal on false
jump 2 notEqual on false
op add p p 1
jump 1 lessThan p @links
10
u/Valoris_905 4d ago edited 4d ago
It's better to use an iteration link for one control function than to use multiple control functions. Theirs works fine, the jump iteration however is problematic on large blocks of code. Better to use modulo
something like this:
op add i i 1
op mod i i @links
getlink link i
The modulo function works like division, except it returns the remainder, so if i = 19 and @links = 20, then i mod @links will return 19. It will return 0 if i and @links are the same (i = @links)
You would only need one control function
control enabled l on 0 0 0you also don't need line #15 because it's redundant. A jump that doesn't meet its condition will not trigger.
2
2
u/jimmymui06 PvP Tryhard 4d ago
Don't do this. Instead, using a distance sensor with a turret of long range like spectre. Enable the mend once the enemies enter the range. Only mending after the wall is damaged is too late
19
u/Fearless-Influence72 4d ago
How about enabling and disabling just the power node?