Page 1 of 1
grid.valid_for_read and item.has_grid Freeze
Posted: Fri May 05, 2017 11:04 pm
by Ranakastrasz
Both of these functions cause the game to freeze if you call them, instead of showing a script error. Neither exist anymore according to the API.
This has made debugging rather frustrating, since I had to restart the game each time an error occured.
There appears to be something similar in this function, but I haven't gotten to investigating yet.
Code: Select all
function tickDummies(id,iSurface,iPosition) -- This and kill dummies need to use a factory. I have no idea what that is. Need research
--GlobalPrint("2")
if not id.units then
id.units = {}
else
-- Already exists.
end
if not id.units.accumulator then
id.units.accumulator = iSurface.create_entity{name = "laser-turret-dummy", position = iPosition, force=game.forces.player}
id.units.accumulator.energy = RanaMods.ModularArmor.config.accumulatorEnergyCap -- initialize energy levels
id.previousEnergy = id.units.accumulator.energy -- and previous energy level from last tick
id.units.accumulator.destructible = false -- Make dummy invulnerable.
else
id.units.accumulator.teleport(iPosition) -- Ensure that the power drain dummy is always at the player's position.
end
end
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Fri May 05, 2017 11:46 pm
by Rseding91
Can you upload your code? I suspect there's an infinite loop in what ever code you're written. When I test it, it simply errors as expected and says they don't exist - no freeze at all.
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Sat May 06, 2017 12:18 am
by Ranakastrasz
That's only a code fragment. Give me a few minutes
More importantly, the code was exactly the same as it was for v0.14.
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Sat May 06, 2017 12:27 am
by Ranakastrasz
Here.
Control.lua
Code: Select all
local armor = thisPlayer.get_inventory(defines.inventory.player_armor)[1] -- Check for armour presence.
if (armor.valid_for_read) then
if (armor.has_grid) then -- Check for grid existence.
local grid = armor.grid
This is the first part that I had to fix, because apperently those functions were removed without telling the script-error-displayer.
The other part is the
Code: Select all
--tickDummies(modularArmor,thisPlayer.character.surface,thisPlayer.character.position)-- validate, create, and move dummy units.
Function, which I commented out the call for. Also commented out a bunch of stuff in that main loop, until I found the offending part.
It all worked fine in v0.14, just when I tried to update to V0.15 that the freeze occurred.
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Sat May 06, 2017 12:32 am
by Nexela
On a side note all that code can be replaced with
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Sat May 06, 2017 12:45 am
by Ranakastrasz
I wish. Unfortunately they added a bunch of validation functions, which makes it all more complex than it needs to be, Used to be, each of those would return nil.
Also, if character is nil, that would fail.
You had to use isvalid functions, ever since those were added. Believe me, I was irritated, because I didn't have to use them before.
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Sat May 06, 2017 1:41 am
by Nexela
Ranakastrasz wrote:I wish. Unfortunately they added a bunch of validation functions, which makes it all more complex than it needs to be, Used to be, each of those would return nil.
Also, if character is nil, that would fail.
You had to use isvalid functions, ever since those were added. Believe me, I was irritated, because I didn't have to use them before.
It would not fail, you are already checking if the character has a player. and .15 allows us to get the grid directly
replace
Code: Select all
local thisPlayer = nil
local players = game.players
for x=1, #players do
thisPlayer = players[x]
if (thisPlayer.connected) then
if (thisPlayer.character) then
WITH
Code: Select all
for x, thisPlayer in pairs(game.connected_players)
if thisPlayer.character then
replace
Code: Select all
local armor = thisPlayer.get_inventory(defines.inventory.player_armor)[1] -- Check for armour presence.
if (armor.valid_for_read) then
if (armor.has_grid) then -- Check for grid existence.
local grid = armor.grid
WITH
Code: Select all
local grid = thisPlayer.character.grid
if grid then
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Sat May 06, 2017 3:22 am
by Ranakastrasz
huh. Nifty.
Good to know.
Still doesn't stop the game from freezing instead of giving an error report tho.
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Sat May 06, 2017 3:37 am
by Rseding91
How can I reproduce the freezing? Do you have a save file and mod with steps I can do to make it happen?
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Sat May 06, 2017 4:12 am
by Ranakastrasz
Add the mod I attached to one of the posts. Use console commands to enable cheat mode and all tech. Craft a modular armor.
Or load any game with modular armor researched and/or crafted.
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Sat May 06, 2017 4:51 am
by Rseding91
Ahhhhhh I see what's happening.
If you look closely you can see it errored but the message is stuck behind the character GUI.
I've fixed it for the next version of 0.15 so the error message is always on top.
Re: grid.valid_for_read and item.has_grid Freeze
Posted: Sat May 06, 2017 2:09 pm
by Ranakastrasz
....
Ohhhhhh.
That makes sense