[0.10.9] print = game.player.print (crashes on call)

Things that we don't consider worth fixing at this moment.
User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

[0.10.9] print = game.player.print (crashes on call)

Post by rk84 »

I should be playing the game, but I'm fooling around with Lua scripts again :)

I get crash if I try to call "game.player.print"-method with variable that refers it directly. Not sure if it is only with print.
This crashes.

Code: Select all

print = game.player.print
print("test")
This works.

Code: Select all

gt = game.gettile
game.player.print( gt(0,0).name )
As a side note I was trying it in closure test and it did print "ModA tick: 0" and crashed after 300 ticks. (Closure test was overall successful after removing the print reference.)

Code: Select all

require "defines"

function initOnTick()
  local tick = 0
  return function(event)
    if event.tick >= tick then
      game.player.print("ModA tick: ".. tick)
      tick = event.tick + 300
    end
  end
end

game.onevent(defines.events.ontick, initOnTick() )
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

kovarex
Factorio Staff
Factorio Staff
Posts: 8195
Joined: Wed Feb 06, 2013 12:00 am
Contact:

Re: [0.10.9] print = game.player.print (crashes on call)

Post by kovarex »

Hello, we are aware of this problem and I'm afraid we will not fix it soon.

The difference is, that with the game.<some method>, it works, because the game object is persistent, it exists all the time during the game, but the game.player<something> doesn't work, as the player object is removed after the game.player is executed.

Generally saving pointers to methods is problematic, and needs to be done with caution (these pointers are not persistent when you save/load the game, so you need to refresh them etc).

The solution to this particular problem is:

Code: Select all

print = function(text) game.player.print(text) end
This way, the player object is evluated every time you call the print.

Moving this to known issues.

User avatar
rk84
Filter Inserter
Filter Inserter
Posts: 556
Joined: Wed Feb 13, 2013 9:15 am
Contact:

Re: [0.10.9] print = game.player.print (crashes on call)

Post by rk84 »

I forgot this has been discussed. Thank you for reply.
Test mode
Searching Flashlight
[WIP]Fluid handling expansion
[WIP]PvP gamescript
[WIP]Rocket Express
Autofill: The torch has been pass to Nexela

Albrat
Inserter
Inserter
Posts: 34
Joined: Tue Feb 17, 2015 2:35 pm
Contact:

Re: [0.10.9] print = game.player.print (crashes on call)

Post by Albrat »

I will also start that you defined a local variable that over-writes a global varible. while the global variable is used in the definition of the new local variable.

print = game.player.print

each "." represents a seperator for command names. so game , player and print are global variables. You defined print as equalling game.player.print (where print now = game.player.print.game.player.print.game.player.print .... Untill you run out of memory. It created a loop that will never break. )

try changing the variable Print to outprint or some other name. It should work.

Post Reply

Return to “Won't fix.”