Adding a flag/property

Place to get help with not working mods / modding interface.
TheSAguy
Smart Inserter
Smart Inserter
Posts: 1456
Joined: Mon Jan 13, 2014 6:17 pm
Contact:

Adding a flag/property

Post by TheSAguy »

Hi,

I'd like to add the following to a unit I convert:

"alert_when_damaged = false"


How would I do that in the below code?

Code: Select all

		  for i, enemy in ipairs(surface.find_enemy_units(beacon.position, global.NE_Buildings.Settings.Search_Distance)) do --search area of ten around each ACS
		  
            if enemy.force == (enemyForce) then --do only if not already controlled
                if math.random(global.minds.difficulty*2)==1 then --easy = 16.5% chance, normal = 10%, hard = 5%              
					enemy.force=beacon.force
					enemy.set_command{type=defines.command.wander,distraction=defines.distraction.by_enemy}
					table.insert(global.minds, enemy)
					
                end
            end
          end
I thought I could add:
enemy.alert_when_damaged = false after "enemy.force=beacon.force"
but that did not work.
User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5211
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Adding a flag/property

Post by eradicator »

The documentation lists alert_when_damaged as a [R]ead-only property and looking at base files one can clearly see that it needs to be added to the prototype, i.e. in data(updates, etc).lua stage. You can't add it dynamically to single units.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.
Post Reply

Return to “Modding help”