[0.11.3+] Update time

This subforum contains all the issues which we already resolved.
User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

[0.11.3+] Update time

Post by L0771 »

I don't know if it is a bug.

Basically i don't know why but this line of code consumes more update time than the others 3k lines

This part of code only gets if you have less health

Code: Select all

		if event.tick % 180 then
			for _,v in ipairs(game.players) do

				local healthless = (game.entityprototypes[v.character.name].maxhealth - v.character.health) -- <----  here

				if healthless > 0 then
					-- ...
				end
				glob.cursed[v.name].aux.lasthp = v.character.health or 100
			end
		end
I've only changed this line with

Code: Select all

local healthless = (100 - v.character.health)
and this is the result
Image

Both are in a new map and just beginning
Before this if set game.speed = 10, I has decreased fps.
Now i can set game.speed = 50 without problems.

It is a big change only with a line, i used the same line in event.tick%30 too without problems, i don't know why.

If you need, here is all the mod, the problem is in the line 777 of control.lua
Rseding91
Factorio Staff
Factorio Staff
Posts: 15902
Joined: Wed Jun 11, 2014 5:23 am
Contact:

Re: [0.11.3+] Update time

Post by Rseding91 »

game.entityprototypes returns a complete list of entity prototypes. You should be storing the maxhealth value in glob.playerMaxHealth[v.character.name] = game.entityprototypes[v.character.name].maxhealth then reference that and it shouldn't take near as much tick time.
If you want to get ahold of me I'm almost always on Discord.
kovarex
Factorio Staff
Factorio Staff
Posts: 8298
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.11.3+] Update time

Post by kovarex »

Yes, the problem is, that you are getting the full list of all prototypes, which is quite a lot of stuff.

The fast solution of this is to get just the prototype you need directly from the character.

Code: Select all

local healthless = v.character.prototype.maxhealth - v.character.health
User avatar
L0771
Filter Inserter
Filter Inserter
Posts: 516
Joined: Tue Jan 14, 2014 1:51 pm
Contact:

Re: [0.11.3+] Update time

Post by L0771 »

Thank you both.
I use entityprototypes a lot of times in the mod :roll:
Post Reply

Return to “Resolved Problems and Bugs”