Page 1 of 1

[0.11.3+] Update time

Posted: Mon Dec 08, 2014 9:10 pm
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

Re: [0.11.3+] Update time

Posted: Tue Dec 09, 2014 7:56 am
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.

Re: [0.11.3+] Update time

Posted: Tue Dec 09, 2014 9:20 am
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

Re: [0.11.3+] Update time

Posted: Thu Dec 11, 2014 4:30 am
by L0771
Thank you both.
I use entityprototypes a lot of times in the mod :roll: