[Solved] Variable in script not changing

Place to get help with not working mods / modding interface.
vedrit
Filter Inserter
Filter Inserter
Posts: 293
Joined: Sun Aug 03, 2014 2:25 am
Contact:

[Solved] Variable in script not changing

Post by vedrit »

Hey all,
My mod is supposed to be set up to where walls/gates will regen health every second, with the regenerated amount increasing with research. The problem is, is that research doesn't seem to be making any difference.

Code: Select all

function heal_wall()
   if global.alienwall ~= nil then
      for k,alienwall in pairs(global.alienwall) do
         if alienwall.valid then
            local HP = alienwall.health
			local hpregen = 5 * global.alienregen
            if HP < 500 then
                NewHP = HP + hpregen
                alienwall.health = NewHP
            end
         else
            table.remove(global.alienwall, k)
         end
      end
   end
end

function init()
   if global.alienwall == nil then
      global.alienwall = {}
   end
   if global.alienregen == nil or global.alienregen == 0 then
      global.alienregen = 1
   end
end

script.on_event(defines.events.on_research_finished, function(event) 
    local research = event.research
    if research == "alien-hybrid-upgrade-1" then
        global.alienregen = 1.2
    end      
    if research == "alien-hybrid-upgrade-2" then
        global.alienregen = 1.6
    end
    if research == "alien-hybrid-upgrade-3" then
        global.alienregen = 2.2
    end
	if research == "alien-hybrid-upgrade-4" then
        global.alienregen = 3
    end
end

script.on_event(defines.events.on_tick, function(event)
		if (game.tick % 60) == 0 then
			heal_wall()
		end
end)
I don't know if it's because the research finish event isn't triggering, or what... Any help would be appreciated
Last edited by vedrit on Sat Apr 09, 2016 2:54 am, edited 1 time in total.
User avatar
DaveMcW
Smart Inserter
Smart Inserter
Posts: 3749
Joined: Tue May 13, 2014 11:06 am
Contact:

Re: Variable in script not changing

Post by DaveMcW »

Code: Select all

script.on_event(defines.events.on_research_finished, function(event)
    local research = event.research.name
vedrit
Filter Inserter
Filter Inserter
Posts: 293
Joined: Sun Aug 03, 2014 2:25 am
Contact:

Re: Variable in script not changing

Post by vedrit »

Ah, that did it. Thanks!
Post Reply

Return to “Modding help”