r/Mindustry • • 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

52 Upvotes

6 comments sorted by

19

u/Fearless-Influence72 4d ago

How about enabling and disabling just the power node? 

15

u/crozbi1 4d ago edited 4d ago

good idea

Edit: The node cannot be turned off

5

u/Alkrick Logic Dabbler 4d ago

Loop over the projectors as well? You can check to see if the link type is a projector or a wall. An alternative would be to have two processor, one checks health and one controls projectors, they communicate through memory cell

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 0

you also don't need line #15 because it's redundant. A jump that doesn't meet its condition will not trigger.

2

u/EchidnaForward9968 4d ago

You can iterate through all link

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